Jump to content
  • Advertisement
Sign in to follow this  
shalrath

Baffeled

This topic is 4726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have created many a win32 window in my time. However, yesterday, when using my basic window creation method, it failed, and I cannot, reguardless of what I try get this to register a window class. Can someone please see if they can see anything wrong with it?
HWND CreateBaseWindow ( HINSTANCE hInst )
{
	//Set up our window class
	WNDCLASSEX wndclass;

	wndclass.cbSize			= sizeof(WNDCLASSEX);		//Set the memory
	wndclass.style			= NULL;//CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
	wndclass.lpfnWndProc	= MsgProc;	//handle messages
	wndclass.cbWndExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= hInst;
	wndclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH)(COLOR_WINDOW);
	wndclass.lpszMenuName	= NULL;
	wndclass.lpszClassName	= TEXT("SimpleWindow");
	wndclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);

	//Register our window class
	if (!RegisterClassEx(&wndclass))									// Attempt To Register The Window Class
	{
		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;											// Return FALSE
	}
	//else success

	return
		CreateWindowEx( NULL, TEXT("SimpleWindow"), "Week1", 
		WS_OVERLAPPEDWINDOW | WS_VISIBLE, GetSystemMetrics(SM_CXSCREEN)/2 - 250, 
		GetSystemMetrics(SM_CYSCREEN)/2 - 187, 500, 375, NULL, NULL, hInst, NULL);
}

Share this post


Link to post
Share on other sites
Advertisement
If you mean it's failing and falling into that if block that pops up a message box and returns false -

RegisterClassEx will set an error which you can retrieve with GetLastError if it returns false.

See what GetLastError gives you, that should either tell you what the problem is, or help us tell you what the problem is [smile].

Share this post


Link to post
Share on other sites
You really should zero out wndclass before using it. just a quick ZeroMemory(&wndclass); before setting its members might solve your problem.

Share this post


Link to post
Share on other sites

CreateWindowEx( NULL, TEXT("SimpleWindow"), "Week1", WS_OVERLAPPEDWINDOW |
WS_VISIBLE, GetSystemMetrics(SM_CXSCREEN)/2 - 250,
GetSystemMetrics(SM_CYSCREEN)/2 - 187, 500, 375, NULL, NULL, hInst, NULL);


Question - what is this TEXT() function and why are you using it here? Duplicating this portion of your code failed to run my test program, specifically the 'TEXT("SimpleWindow")' part (well, it didn't run in any visible shape or form but it also gave no error messages)


-Greven

Share this post


Link to post
Share on other sites
Quote:

Question - what is this TEXT() function and why are you using it here? Duplicating this portion of your code failed to run my test program, specifically the 'TEXT("SimpleWindow")' part (well, it didn't run in any visible shape or form but it also gave no error messages)

It is not a function; it is a macro(AFIAK).
What it does is it supports unicode support.if it runs under a unicode program, it converts the string to unicode, but if it isnt unicode it just returns the string.

Share this post


Link to post
Share on other sites
Ah, I see. Well, that wasn't it, then.

shalrath, are you certain no other portions of your code are responsible for this? I haven't really seen anything else that looks questionable.

edit:

Just saw this:

wndclass.cbWndExtra = 0;
wndclass.cbWndExtra = 0;

While not a program-stopping error, I assume you meant:

wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;

-Greven

Share this post


Link to post
Share on other sites
Quote:
Original post by shalrath
I guess it wasn't allocating memory, the ZeroMemory call fixed it, thanks chad_420.

By "allocating the memory", I assume you mean "zeroing the memory" (!!!).
(ZeroMemory does absolutly nothing like alocating)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!