Hi guys,
I'm going apeshit over a modeless dialog I'm trying to create. I don't know what I'm doing wrong but it's completely breaking my application.
It's just supposed to be an about-box with an ok button, but nooo, the "Ok" button doesn't even show, and the whole program acts weird. I created a template in memory rather than use a resource since I don't have an editor and I'd like to learn how they are built. I tested the template in modal mode using DialogBoxIndirect and everything worked fine. Now I use CreateDialogIndirect and add a few changes and everything screws up, and I don't know why.
here is my WndProc function in main.cpp:
...
// Global handles.
HWND hDlgHelpAbout = NULL;
...
// Window Procedure function definition.
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
// Create the menu.
initMenu(hWnd);
break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case ID_HELP_ABOUT:
if (!IsWindow(hDlgHelpAbout))
{
// Create "About" dialog.
LPDLGTEMPLATE lpDlgTemp = createHelpAbout(hWnd);
hDlgHelpAbout = CreateDialogIndirect(GetModuleHandle(NULL), lpDlgTemp, hWnd, (DLGPROC)helpAboutProc);
GlobalFree(lpDlgTemp);
// Show it too.
ShowWindow(hDlgHelpAbout, SW_SHOW);
}
break;
case ID_FILE_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
}
}
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
DestroyWindow(hDlgHelpAbout);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
and here are the function I use to create the template and the dialogs procedure function (in another .cpp file):
#include <windows.h>
#include "ids.h"
#include "dialogTemplate.h"
#include "dialogFunctions.h"
BOOL CALLBACK helpAboutProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
DestroyWindow(hWnd);
return TRUE;
}
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
case WM_CLOSE:
DestroyWindow(hWnd);
return TRUE;
}
return FALSE;
}
LPDLGTEMPLATE createHelpAbout(HWND hWnd)
{
// Handle to the memory.
HANDLE hGlobal = GlobalAlloc(GMEM_ZEROINIT, 1024);
LPWORD lpw = createDlgHeader(hGlobal, "About", DS_SETFONT | DS_CENTER | DS_3DLOOK | WS_POPUP | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION, 1, 8, "MS Sans Serif", 0, 0, 319, 47);
lpw = createDlgCtrl(lpw, BUTTON_CLASS, IDOK, "Ok", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON, 264, 7, 48, 15);
return (LPDLGTEMPLATE)hGlobal;
}
I know I should be setting hDlgHelpAbout to NULL in the WM_CLOSE of the dialogs procedure, but I'll take care of that later, that can't be the problem. That should only hinder it from being created again.
Also, the close buttons (the "X") doesn't work either.
Anyone know why this might be?
Cheers