From: voidnull on
I'm trying to create a custom class name for my modeless dialog box.
The following shows a snippet from my .rc file and the code to create
the dialog. Everything works fine until I get a NULL handle returned
with CreateDialog (which I understand to be a wrapper for
CreateWindowEx). The GetLastError is ERROR_SUCCESS. I'm not
understanding what I'm doing wrong here.


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

HWND hwndDlg = NULL;
WNDCLASSEX wcx;

if(!GetClassInfoEx(hInst,"#32770",&wcx))
ErrorExit(TEXT("GetClassInfoEx"));
wcx.lpfnWndProc = DlgResultsProc;
wcx.cbSize = sizeof(wcx);
wcx.lpszClassName = "MyClass";
if(!RegisterClassEx(&wcx))
ErrorExit(TEXT("RegisterClassEx"));

//create a modless (non-blocking dialog box)
hwndDlg = (HWND)CreateDialog(hInst,
MAKEINTRESOURCE(IDRESULTS),
hwnd, //this is the handle to the main window that owns it
DlgResultsProc); //pointer to dialog box procedure
if(hwndDlg == NULL)
ErrorExit(TEXT("CreateDialog"));
ShowWindow(hwndDlg,SW_SHOW); // Make the window visible
UpdateWindow(hwnd); //redraw the window
return hwndDlg;
From: Alf P. Steinbach on
* voidnull:
> I'm trying to create a custom class name for my modeless dialog box.
> The following shows a snippet from my .rc file and the code to create
> the dialog. Everything works fine until I get a NULL handle returned
> with CreateDialog (which I understand to be a wrapper for
> CreateWindowEx). The GetLastError is ERROR_SUCCESS. I'm not
> understanding what I'm doing wrong here.
>
>
> 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
>
> HWND hwndDlg = NULL;
> WNDCLASSEX wcx;
>
> if(!GetClassInfoEx(hInst,"#32770",&wcx))
> ErrorExit(TEXT("GetClassInfoEx"));
> wcx.lpfnWndProc = DlgResultsProc;
> wcx.cbSize = sizeof(wcx);
> wcx.lpszClassName = "MyClass";
> if(!RegisterClassEx(&wcx))
> ErrorExit(TEXT("RegisterClassEx"));
>
> //create a modless (non-blocking dialog box)
> hwndDlg = (HWND)CreateDialog(hInst,
> MAKEINTRESOURCE(IDRESULTS),
> hwnd, //this is the handle to the main window that owns it
> DlgResultsProc); //pointer to dialog box procedure
> if(hwndDlg == NULL)
> ErrorExit(TEXT("CreateDialog"));
> ShowWindow(hwndDlg,SW_SHOW); // Make the window visible
> UpdateWindow(hwnd); //redraw the window
> return hwndDlg;

You're using DlgResultsProc both as a window procedure and as a dialog
procedure. If it is a dialog procedure then it's unsuitable as a window
procedure, and vice versa. That *may* be your problem, or at least 1.


Cheers & hth.,

- Alf