Click to See Complete Forum and Search --> : RegisterClassEx failure.


indiocolifa
September 13th, 2003, 05:02 PM
I'm doing the following to create a new class based on the system dialog class (#32770) to do my program's main window, which of course, is a dialog.

The code that fails:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
PSTR cmdLine, int nCmdShow)
{
static char szClassName[] = "MCW";
HWND hwnd;
MSG msg;
WNDCLASSEX wcex;
HACCEL hAccel;

// Get the class for the system dialog class
wcex.cbSize = sizeof(WNDCLASSEX);
GetClassInfoEx(NULL, "#32770", &wcex);

// Register class
wcex.lpszClassName = szClassName;
wcex.cbClsExtra = 0;
wcex.hInstance = hInstance;
wcex.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE( IDI_MCWICON));
wcex.hIconSm = LoadIcon (hInstance, MAKEINTRESOURCE( IDI_MCWICON));
wcex.cbWndExtra = DLGWINDOWEXTRA;
wcex.lpfnWndProc = WndProc;
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);

RegisterClassEx(&wcex);

if (!RegisterClassEx(&wcex))
{
MessageBox (NULL, "Error in RegisterClassEx", "error", MB_ICONERROR);
return 0;
}



Why this fails?

filthy_mcnasty
September 13th, 2003, 06:09 PM
GetClassInfoEx(NULL, "#32770", &wcex);

i'm not entirely sure why you do this when you just go and fill the structure in manually anyways.

at any rate your code fails because you're trying to register the same class twice. it works but it will always cause your error handler to run.

RegisterClassEx(&wcex);
if (!RegisterClassEx(&wcex))
etc


just remove the first line there and you should be good.