Windows Dialog box problem

Started by
7 comments, last by Shadwdrak 23 years, 9 months ago
I am writing a simple program to hopefully learn how to use Windows Dialog boxes. Here is my code. // Includes #include #include #include "resource.h" // Windows function prototypes LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); // Main window procedure //bool CALLBACK AboutProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam); // About box window procedure bool CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM); // About box window procedure HWND hwnd; // Handle to the window /////////////////////////////////////// //// WINMAIN ////////////////////////// /////////////////////////////////////// int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("Map Editor"); MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW / CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (hInstance, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); wndclass.lpszClassName = szAppName; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, // class name; szAppName, // window name; WS_OVERLAPPEDWINDOW, // window style; CW_USEDEFAULT, CW_USEDEFAULT, // starting position (x,y); CW_USEDEFAULT, CW_USEDEFAULT, // width and height; NULL, // parent handle; NULL, // menu handle; hInstance, // instance handle; NULL); //pointer to window creation data ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); while (TRUE) { if(PeekMessage (&msg, NULL, 0,0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage (&msg); DispatchMessage (&msg); } else { // This is the main game loop (DUH!!!) } } return msg.wParam; }; /////////////////////////////////////// //// WNDPROC ////////////////////////// /////////////////////////////////////// LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HINSTANCE hInstance; switch (message) { case WM_CREATE: hInstance = ((LPCREATESTRUCT) lParam)->hInstance; return 0; case WM_KEYDOWN: switch (wParam) { case VK_ESCAPE: break; } return 0; case WM_MOUSEMOVE: return 0; case WM_COMMAND: switch(LOWORD(wParam)) { case ID_EXIT: PostQuitMessage(0); return 0; case ID_ABOUT: DialogBox(hInstance, TEXT ("AboutBox"), hwnd, AboutProc); // instance handle return 0; } return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }; ////////////////////////////// // PROGRAM ABOUT BOX ////////////////////////////// bool CALLBACK AboutProc(HWND hwndAbout, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: return true; } return FALSE; case WM_CLOSE: EndDialog(hwndAbout, IDOK); return TRUE; } return FALSE; } When I try to compile the program I get the following error: error C2664: ''DialogBoxParamA'' : cannot convert parameter 4 from ''bool (void *,unsigned int,unsigned int,long)'' to ''int (__stdcall *)(void)'' If anyone has a clue as to the nature of this error any and all help would be appreciated. -Shadwdrak
Advertisement
ok, ive done the same thing before... basically, you had the dialog boxs wnd proc return value type set to bool when it should be BOOL. yes, there is a difference. the DialogBox function expects the BOOL which is a typedef for an unsigned int where as bool is an actual basic type. anyways, that should do it. happy dialonging.

hint: learn MFC, it''s MUCH easier than straight WinApi code...

david
--david@neonstar.netneonstar entertainment
hint: only use MFC for your level editors

hint, hint: Make your game with the CWindowImpl class in the ATL (Active Template Library) and forget about MFC in your game engine.

"Do you bury me when I'm gone?
Do you teach me while I'm here?"
- James Hetfield
Yeesh, it''s not like he asked for opinions.

In any case, Mr. Borromeo was correct that a bool is different from a BOOL.

bool == char (i.e, a 1 byte variable)
BOOL == unsigned int (4 byte variable)
BLEH! i never intended to encourage using MFC in a game engine... i dunno how i could have made my post sound like that, but oh well.

i''m just using pure WinAPI for game engine. only the WinMain loop. otherwise, it''s all DirectX code and game logic ...

mfc is only good for windowsy-type programs, definitely not for games...

david
--david@neonstar.netneonstar entertainment
MFC is the devil.

IMHO you learn more by NOT using MFC. Plus there''s alot less overhead since you write only the code you need.

-Zims
Well thanks for all the feed back... I changed the type from bool to BOOL. Now I get an error that is almost the same as the last one.

error C2664: ''DialogBoxParamA'' : cannot convert parameter 4 from ''int (void *,unsigned int,unsigned int,long)'' to ''int (__stdcall *)(void)''

When I started this program I didnt intend to have this much trouble with a simple dialog box...

-Shadwdrak
yeah, you''re right, there''s a lot less overhead, plus you don''t have to either statically link the library or link a DLL if you use straight Win code. i just like using MFC cause it''s much faster than straight Win code. plus the overhead really doesn''t bother me because the app really doesn''t run that slow, even on a slow computer. a 3D modeller in MFC would, i''m sure...



dave
--david@neonstar.netneonstar entertainment

This topic is closed to new replies.

Advertisement