Hello all, I've recently made a maze game with win32 and ran into a weird problem, I've solved it, but it left me with questions.
In WinMain() we have the registration of a child class called "Cell" like this:
Code:
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = CellProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = sizeof( Cell* ) ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = NULL ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW ) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = TEXT("Cell") ;
if( !RegisterClass( &wndclass ) )
{
MessageBox( NULL, TEXT("Error registering \"Cell\" class, closing\n"), TEXT("Error"), MB_OK );
SendMessage( hwndBoard, WM_CLOSE, 0, 0 );
return 0;
}
The RegisterClass() function returns successfully. Then later in the "board.cpp" module, I call CreateWindow() to create the "Cell" windows, with the HINSTANCE value that was passed into WinMain (this is inside a loop):
Code:
HWND winCell = CreateWindow( TEXT("Cell"),
NULL,
WS_CHILD | WS_VISIBLE,
rcCell.left,
rcCell.top,
rcCell.right,
rcCell.bottom,
winBoard,
( HMENU ) i * iWidth + j,
hInst,
( PVOID ) this );
This call fails, and the error code is 1407 (Can not find window class). I solved this by just moving the registration into the "board.cpp" module.
However this left me with questions I wasn't able to find very good answers to:
1. Is the memory used to hold the value passed into RegisterClass() unique to each module, and if so how is win32 identifying the callers module?
2. Would it be possible to keep the RegisterClass() call in one module while creating the window in another, and if so how?
Thanks!
( PS. In the last iteration of the program I've removed the "Cell" windows completely, but I would like to figure this out. I might post the game when done, as it has a pretty interesting mechanic. ).