-
Dialogs and stuff
Okay, I've only been trying to use the Win32 API for a short time but thought I was making great progress. Until now. I had written a small program in MSVC 6 that basically just displayed a modeless dialog (Or modal...I may have them backwards, but it's the one where the dialog doesn't have to be destroyed to return to the parent). It worked fine. Now I'm trying to do a real program and for some reason, I can't do the same thing. No matter what I try, I can't get a simple dialog to display. Message boxes are fine, but no dialogs. Instinct tells me that I have my dialog set up improperly but I can't find where and I really don't know for sure anyway. Here's some code :
Code:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
CreateDialog(myInstance, MAKEINTRESOURCE(IDD_MAIN), hwnd, MainProc);
break;
case WM_COMMAND:
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
BOOL CALLBACK MainProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
return true;
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
}
break;
default:
return false;
break;
}
return true;
}
The parent window itself displays fine. A great big white box. Yay.
Here's the bit of the .rc file with my dialog:
IDD_MAIN DIALOG DISCARDABLE 0, 0, 449, 206
STYLE WS_CHILD | WS_VISIBLE | WS_THICKFRAME
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Yeah, this blows.",IDC_STATIC,63,36,172,72
END
If you need more, just let me know.
-
I presume your myInstance is a global variable. Are you sure you have initialised it?
-
Yeah, it's global because I know I'm going to need to manipulate later in other functions. Yeah, it's initialized. At least, would the main window have come up if it hadn't been? Hmmm...I wonder...
-
Here's my WinMain method :
Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
myInstance = hInstance;
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = myInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(NULL);
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL , "Failed to register window class", "Error" , MB_ICONEXCLAMATION | MB_OK );
return 0;
}
HWND hwnd;
int cx, cy;
cx = GetSystemMetrics(SM_CXMAXIMIZED);
cy = GetSystemMetrics(SM_CYMAXIMIZED);
//char data[10];
//sprintf(data, "%d, %d", cx, cy);
//MessageBox(NULL, data, "Message", MB_OK);
if(cx >= 1024)
cx = 1024;
if(cy >= 746)
cy = 746;
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "ASP Menu Configuration", WS_OVERLAPPEDWINDOW,
0, 0, cx, cy, NULL, NULL, myInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Failed to create window", "Error", MB_ICONEXCLAMATION | MB_OK );
return 0;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
MSG Msg;
while(GetMessage(&Msg,NULL,0,0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
-
I figured it out. And man, do I feel foolish. :P
I hadn't added the resource.h header or script.rc files to the fileview in MSVC. Thing is, since it was compiling fine, I didn't even think about this, but I suppose it must look for the data at runtime. Which makes a lot of sense......maybe. Sometimes I want to find the person that invented computers and stab him in the face. Debugging makes working at A&W for the rest of my life seem mild in comparison.