Skip to main content
GameDev.net gamedev.net
🔒 Locked

CreateWindow problems

Started by Velochy Oct 9, 2002 at 2:48 PM 10 replies 2.7k views
Original Post
Velochy
Velochy
This is my Window procedure which keeps giving me an Error 2: 1400 message box AKA it cannot create the MainWnd.. anyone got any ideas as to what might be causing it?
  
void cApp::CreateMainWindow(int ShowCode)
{
	const char ClassName[] = "MyGame";
	WNDCLASSEX WndCX =
				{ sizeof(WNDCLASSEX),CS_CLASSDC, (WNDPROC)MessagePump,0,0,hInstance,NULL,NULL,(HBRUSH)(COLOR_BACKGROUND),NULL, "MyGame",NULL};

	if (!RegisterClassEx(&WndCX))
	{
		char error[256];

		sprintf(error, "Error1 %u", GetLastError());
		MessageBox(NULL, error, "Error!",MB_ICONEXCLAMATION | MB_OK);
		TerminateProgram();
	}

	MainWnd=CreateWindow("MyGame", "Velochy", WS_POPUP | WS_EX_TOPMOST, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200, NULL, NULL, hInstance, NULL );

	if (MainWnd==NULL)
	{
		char error[256];

		sprintf(error, "Error2 %u", GetLastError());
		MessageBox(NULL, error, "Error!",MB_ICONEXCLAMATION | MB_OK);
		TerminateProgram();
	}

	ShowWindow(MainWnd, ShowCode);
    UpdateWindow(MainWnd);

	return;
}
  
Ersvik
Ersvik
The WS_EX_TOPMOST flag should not be used like that I think. In order to use the extended flags you''ll have to call CreateWindowEx(...).

Hope this helps,

Johan Ersvik
Johan
Velochy
Velochy
nope, tried that.. tried with cmpletely other flags (standard, no _EX_ es) and still didnt work.. im guessing the problem lies in some other argument
ironpoint
ironpoint
First I would try

GetSysColorBrush(COLOR_BACKGROUND)

instead of typecasting COLOR_BACKGROUND

And also you might need a WS_VISIBLE
CaptainJester
CaptainJester
It might be because you are trying to do in in a class. I know this can cause all sorts of problems. I copied your code and it compiled and ran fine for me. The only difference is that I did not put the code inside a class.



Make it work.
Make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Velochy
Velochy
nope, didnt really work
could anyone take the time to actully try this function in their program.. perhaps the error is somewhere else.. altho it seems highly unlikely.
ANy other ideas anyone?

Update:
okay, ill try to take it out of a class and see what happends, thanx for compiling

[edited by - Velochy on October 10, 2002 8:38:09 AM]
Velochy
Velochy
and nope, takin it out of a class did jack for the code

perhaps it is something that has to be done before the window creation that i didnt include in the program.. this is the first function called.. the hInstance and ShowCode are both valid(given by windows and passed on directly) but if something needs to be done before these things described in CreateMainWindow, i would really like to know about them
Darrell L
Darrell L
Having the code in a class member function is fine.

What does your WM_NCCREATE/WM_CREATE processing code look like? Are you returing from your handler during the processing of these msgs with your own return, or with the returned value from DefWindowProc?

If you''re returing with your own value, then you need to make sure they''re the right ones to indicate that the creation process should continue. I think it''s 1 for WM_NCREATE and 0 for WM_CREATE. But it''s best just to let DefWindowProc return the appropriate value.
Velochy
Velochy
ehem, could anyone translate that to newbie? really didnt understand much of that text on the first run.. well ill try again and see what happends
thanx anyways
Velochy
Velochy
Actually, that is where the dog was bueried - my wndProc always returned 0 no matter... once i made it return the DefWindowProc all was nice just like it should have worked.. thanx to all
Galapaegos
Galapaegos
Have you looked to see if the window was created? (ie in win2k and xp press alt-ctl-del and go to the processes. You can also use Spy++ ) Is your program listed? If so, then change your ShowCode to something like SW_SHOW. Good luck!

Brad
-brad
mutex
mutex
Casting COLOR_BACKGROUND to HBRUSH is correct, but you need to do (HBRUSH)(COLOR_BACKGROUND+1), I think. That will set the background color to COLOR_BACKGROUND. You can do that instead of creating a brush. Read the docs to make sure what I''ve said is correct.

Try this for window flags: WS_VISIBLE|WS_OVERLAPPEDWINDOW. If that works, then you''re probably passing an invalid combination of window flags, which seems to be my most common source of window creation failure.

Topic Locked

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

Sign in to reply to this topic.