Help with Creating a Custom Class for a modeless dialog popup
Hello all,
I desire to create a modeless dialog with a custom class. The dialog
is created as a form. The code below shows what I'm doing. Yet
CreateDialog always returns NULL. I guess I don't know what I'm doing
wrong...
Code:
IDRESULTS DIALOGEX 0, 0, 412, 232
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX |
WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_CONTROLPARENT
CAPTION "Results"
CLASS "MyClass"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
END
Code:
HWND RegisterResultsDlg(HINSTANCE hInst, HWND hwnd)
{
HWND hwndDlg;
WNDCLASS wc;
GetClassInfo(hInst,"#32770",&wc);
wc.lpfnWndProc = DlgResultsProc;
wc.lpszClassName = "MyClass";
if(!RegisterClass(&wc))
{
MessageBox(NULL, "Failed to Register Custom Dialog Class!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return NULL;
}
hwndDlg = (HWND)CreateDialog(hInst, "MyClass",
hwnd, DlgResultsProc);
if(hwndDlg == NULL)
{
MessageBox(NULL, "Failed to Create Results Dialog Box!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return NULL;
}
ShowWindow(hwndDlg,SW_SHOW);
return hwndDlg;
}
Re: Help with Creating a Custom Class for a modeless dialog popup
The second parmeter of CreateDialog is not the window class name but the dialog template name.
In your particular case it has to be MAKEINTRESOURCE(IDRESULTS).
It is not possible to create a dialog with custom class name by calling CreateDialog. Instead, you have to use CreateWindowEx function.
CreateDialog calls CreateWindowEx and performs some additional tasks like sending WM_INITDIALOG messge and so on.
So... it's a little bit to sweat. ;)