Skip to main content
gamedev.net
🔒 Locked

Win32 CreateWindowEx()

Started by TheRealBartman 1 reply 250+ views
Original Post
TheRealBartman
TheRealBartman
Hey everyone, I have spent the last several hours attempting to figure out why my win32 application I wrote for practice earlier decided to stop working. What I mean by stop working is this: After it registers the windows class via RegisterClassEx(), I use CreateWindowEx() to attempt creating the window. I have never had a problem until earlier tonight, when for no apparent reason it began return a NULL hwnd each time. The odd thing is, any Win32 code that I have written before tonight still compiles and runs perfectly. I decided to write a short application for testing and as an example to show my problem.
    
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	return DefWindowProc(hWnd,msg, NULL, NULL);
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	WNDCLASSEX WndClsEx;
	MSG msg;

	memset(&WndClsEx, 0, sizeof(WndClsEx));

	WndClsEx.cbSize = sizeof(WndClsEx);
	WndClsEx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	WndClsEx.hInstance = hInstance;
	WndClsEx.lpfnWndProc = WndProc;
	WndClsEx.lpszClassName = "TEST";
	WndClsEx.style = CS_HREDRAW|CS_VREDRAW;

	RegisterClassEx(&WndClsEx);

	HWND hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "TEST", "TEST", WS_OVERLAPPED, 0, 0, 640, 480, NULL, NULL, hInstance, NULL);

	ShowWindow(hWnd, SW_SHOW);

	while(GetMessage(&msg, hWnd, NULL, NULL))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return 0;
}
    
I would appreciate any help that I recieve, because as of right now I am completely stumped as to why this is going on. I am running this on Windows2k Professional with all of the Service Packs. Thanks! Michael Bartman [edited by - TheRealBartman on January 26, 2003 2:25:35 AM] [edited by - TheRealBartman on January 26, 2003 2:31:50 AM]
Michael BartmanLead ProgrammerDark Omen Studios
niyaw
niyaw
quote:
Original post by TheRealBartman
return DefWindowProc(hWnd,msg, NULL, NULL);


that's your problem. you're passing 0 as wparam and lparam to defwindowproc, which makes it hard to do useful things as a response to i.e. WM_NCCREATE. fixed by

return DefWindowProc(hWnd,msg, wParam, lParam);

don't forget to call PostQuitMessage at some point, as your present program never terminates.

[edited by - niyaw on January 26, 2003 2:39:36 AM]
TheRealBartman
TheRealBartman
Niyaw,

I have always passed null for WPARAM and LPARAM in the past,
Oddly enough it only just now started to matter.

Thank you!



[edited by - TheRealBartman on January 26, 2003 2:49:09 AM]

[edited by - TheRealBartman on January 26, 2003 2:50:18 AM]
Michael BartmanLead ProgrammerDark Omen Studios

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.