Click to See Complete Forum and Search --> : CreateWindow failing?


MrDoomMaster
November 27th, 2004, 08:59 PM
I must be stupid, I don't know why this isn't working:


//====================================================================================
/*
|| Creates a window for the game
|| Returns NULL if failed, the window handle if successful.
*/
HWND DirectX_Utils::GameWindowCreate(string WindowTitle)
{
WNDCLASS CS;

CS.cbClsExtra = 0;
CS.cbWndExtra = 0;
CS.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
CS.hIcon = NULL;
CS.hCursor = NULL;
CS.hInstance = GlobalInstance;
CS.lpfnWndProc = WindowProcedure;
CS.lpszClassName = "GameAppClass";
CS.lpszMenuName = 0;
CS.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_OWNDC;

if(!RegisterClass(&CS))
return NULL;

return (MainWindow = CreateWindow("GameAppClass", WindowTitle.c_str(), WS_POPUP | WS_VISIBLE,
100, 100, 300, 300, NULL, NULL, GlobalInstance, NULL));
}


CreateWindow returns NULL!

GlobalInstance and WindowProcedure are both private members of my class, which are initialized appropriately at construction.

MainWindow is a private member also which receives the handle to the window.

Marc G
November 28th, 2004, 02:47 AM
What is WindowProcedure? Is this window procedure a member of your class? You can't use a function pointer to a member of your class for use as a window procedure.

Andreas Masur
November 28th, 2004, 03:00 AM
Well...as usual...what does 'GetLastError()' return? For further information take a look at the following FAQ (http://www.codeguru.com/forum/showthread.php?t=318721)...

Elementer
November 28th, 2004, 06:49 AM
Have you declared the function "WindowProcedure" as follow ?

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch(uiMsg)
...
...
return DefWindowProc(...);
}

If yes, try this 2 way:

CreateWindow("GameAppClass", WindowTitle.c_str(), WS_POPUP | WS_VISIBLE,
100, 100, 300, 300, NULL, NULL, GlobalInstance, (void*)this);

or

CreateWindow("GameAppClass", WindowTitle.c_str(), WS_POPUP | WS_VISIBLE,
100, 100, 300, 300, NULL, NULL, GetModuleHandle(NULL), NULL;

I don't kwno how your complete class is, maybe these can cause an error...

EDIT:
I have forgotten:
are you creating a fullscreen window or a window-mode one ? If window-mode, you must specify WS_CLIPCHILDREN | WS_CLIPSIBLINGS flags besides WS_POPUP | WS_VISIBLE...
If you're creating a fullscreen window, the probrem can rise becouse you choose a resolution that your hardware/system doesn't supports

Also I recommend you to use CreateWindowEx(....) in the future...


:)

MrDoomMaster
November 28th, 2004, 10:27 AM
Ooops.... I didn't put this at the end of my Window Proc:


return DefWindowProc(hwnd, msg, wparam, lparam);


*slaps himself*