Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
Posted

1 solution

I figured it out. This is how I did it:

HWND hwndDlg = NULL;
WNDCLASSEX wcx;

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

//create a modless (non-blocking dialog box)
hwndDlg = (HWND)CreateDialog(hInst, //handle to the executable of this program
MAKEINTRESOURCE(IDRESULTS), //select the dialog box template to display
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;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900