I have a dialog box that I am using for user input, and it was working just fine, now no matter what I do the dialog pops up for one second and then the program dies with no warning, calling WM_DESTROY
even after I comment out all the possible exits. There is only one error, which is the no_init_all
error, but that shows up every time there is a runtime error, and is pretty useless in trying to find the solution.
Here is my code:
project.cpp
BOOL CreateMyDialog(HINSTANCE hInstance) {
HWND hWnd = CreateDialog(NULL, MAKEINTRESOURCE(myDialogResource), NULL, (DLGPROC)myDialogProcess);
if (!hWnd) {
return FALSE;
}
myDialogGlobalHandle = hWnd;
ShowWindow(hWnd, SW_SHOW);
//UpdateWindow(hWnd);
return TRUE;
}
INT_PTR CALLBACK myDialogProcess(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
INITCOMMONCONTROLSEX InitCtrlEx;
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrlEx.dwICC = ICC_PROGRESS_CLASS;
InitCommonControlsEx(&InitCtrlEx);
switch(msg) {
case WM_INITDIALOG: {
//Do stuff to prep the dialog
return TRUE;
}
case WM_DESTROY: {
PostQuitMessage(WM_QUIT);
break;
}
}
return TRUE;
}
project.rc
myDialogResource DIALOGEX 600, 400, 286, 108
STYLE DS_SYSMODAL | DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION
EXSTYLE WS_EX_OVERLAPPEDWINDOW /*| WS_EX_APPWINDOW*/
CAPTION "My Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
COMBOBOX dropdownList,112,7,61,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
//... it's all syntactically correct controls that still work the split second the dialog is on the screen
END
This is the shortened code, and even with this the dialog opens on top of itself and glitches on the screen. With my full code, it appears normally for a split-second before the app closes. I believe if I can fix this small bit, I can find the issue with my dialog. So my question is, what's the issue?
EDIT:
Here is my wWinMain
:
HWND myDialogGlobalHandle;
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
INITCOMMONCONTROLSEX InitCtrlEx;
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrlEx.dwICC = ICC_PROGRESS_CLASS;
InitCommonControlsEx(&InitCtrlEx);
if (!CreateMyDialog(hInstance)) {
//return FALSE;
}
else {
MSG message = { 0 };
while (GetMessage(&message, nullptr, 0, 0)) {
if (!IsDialogMessage(myDialogGlobalHandle, &message)) {
DispatchMessage(&message);
}
}
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PROJECT));
MSG msg;
// Main message loop:
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}