Click to See Complete Forum and Search --> : GUI Not Showing


chris95219
December 2nd, 2006, 09:16 PM
Okay, this has been bugging me for the past week or so.. i've been trying everything i can to find the bug.. but.. no luck. My GUI just won't show up. I checked the value of the hWnd and it is showing up as null.. so the CreateWindowEx() function isn't working for me.

Anyone care to take a look? Greatly appreciated!!!!!!


Window(WNDPROC WndProc, char* sTitle, int nX, int nY) {
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT(sTitle);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc);
this->hWnd = ::CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(sTitle), sTitle, WS_OVERLAPPEDWINDOW, nX, nY, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);

::ShowWindow(hWnd, SW_SHOW);
::UpdateWindow(hWnd);
}


i have a window class and that is the constructor.

and here is how im trying to use it:


MSG msg;
Window * myWindow = new Window(MyFunc, "test", 0, 0);


and i do have a while loop to keep it running.

UnfitElf
December 2nd, 2006, 09:53 PM
Hey :)

First thing i saw (there may be others but i stoped checking) was that you are passing in "test" as the title..

but then your createwindowex function is like this

CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(sTitle), sTitle, WS_OVERLAPPEDWINDOW, nX, nY, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);

// the 2nd parameter need to be a predefined Class name, or a window you have resgistered (you have not shown any code of registering a window so i assume your not doing it)
Click here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/createwindowex.asp)

You need to register your window, or use a predefined clas name :)

Hope this helps

chris95219
December 3rd, 2006, 01:05 AM
What about my WC window class that I registered?

kkez
December 3rd, 2006, 04:51 AM
The code you posted seems correct. Now, post the WndProc's WM_CREATE. Usually if you do something bad in WM_CREATE, CreateWindow fails, since this function doesn't return until WM_CREATE is processed.

ovidiucucu
December 3rd, 2006, 07:13 AM
I checked the value of the hWnd and it is showing up as null.. so the CreateWindowEx() function isn't working for me.

MSDN
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Check also if RegisterClassEx has succeeded or not.
And see also this FAQ (http://www.codeguru.com/forum/showthread.php?t=318721).

Calculator
December 3rd, 2006, 09:41 AM
TEXT(sTitle)

I don't think that that is something you can do. Instead of that, just change the function decl;aration.

Window(WNDPROC WndProc, LPCTSTR sTitle, int nX, int nY)

chris95219
December 3rd, 2006, 05:00 PM
well... apparently all my code was coorect... but i found this:
http://www.gamedev.net/reference/articles/article1810.asp

its not as simple as i thought :(


thanks everyone.