Hi. I just started writing an API app in MSVC so that I could use a dialog resource instead of CreateWindow() to create all of my controls and such.. Anyway, in WinMain() I am calling CreateDialog() but it is returning NULL. I simply can not figure out why.. I figure that is the only reason that nothing happens when I run the program (the dialog doesn't ever become visible, but the beep of the MessageBox() is heard). Also, my dialog does have the WS_VISIBLE flag, in case you're wondering. My WinMain() follows.
Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
HWND hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, (DLGPROC)WindowProc);
if (!hwnd) {
MessageBox (NULL, "Can't create Dialog", NULL, MB_OK);
return 1;
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
[EDIT]
I've inserted some diagnostic output and this is what's happening:
Before CreateDialog
top of WindowProc
WM_SETFONT
top of WindowProc
WM_DESTROY
top of WindowProc
WM_NCDESTROY
After CreateDialog
leaving WinMain
So, at the call of CreateDialog() 3 messages are sent to the DlgProc (note that WM_INITDIALOG is not one of them): WM_SETFONT, WM_DESTROY, WM_NCDESTROY... Iow, after WM_SETFONT is called, the window is destroyed and this all happens before the call to CreateDialog() is even completed! What's going on? Come on API programmers. One of you has to have some insight...