Sign in to follow this  

CreateWindowEx() - FAILED [SOLVED]

This topic is 4688 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'm having some trouble creating a window in a relatively simple DirectX program (though the fact that it uses DirectX shouldn't matter, since the program fails before it gets to that stuff). Anyways, it's probably some dumb mistake I'm oblivious to: I have a global window handle, like so: HWND g_hWnd; My WinMain():
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, INT )
{
	RegisterWindowClass( hInstance );
	CreateAppWindow( hInstance );
	ShowWindow( g_hWnd, SW_SHOWDEFAULT );
	UpdateWindow( g_hWnd );

	BOOL bWindowed = InitApp();
	if( InitDirect3D( bWindowed ) && Setup() )
	{
		WPARAM result = StartMessageLoop();
	}
	
	CleanUp();
	return 0;
}


Nothing surprising about that. Here is another "standard compliance" function, RegisterWindowClass() (I'll get to CreateAppWindow() - it's probably the source of the error, so I want to get all the standard stuff out of the way):
////////////////////////////////
// RegisterWindowClass()
////////////////////////////////
void RegisterWindowClass( HINSTANCE hInstance )
{
	WNDCLASSEX wc;
	wc.cbSize = sizeof( WNDCLASSEX );
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	wc.hCursor = (HCURSOR)LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "D3D";
	wc.hIconSm = NULL;
}


And finally, though I could have sworn that I copied it out of my book exactly, here's the probably problematic (but not guaranteed problematic, since I have totally no idea where the error is coming from) CreateAppWindow():
////////////////////////////////
// CreateAppWindow()
////////////////////////////////
void CreateAppWindow( HINSTANCE hInstance )
{
	g_hWnd = CreateWindowEx(
		NULL, "D3D", "D3D Windowed VS Full Test",
		WS_OVERLAPPEDWINDOW, 100, 100, 800, 600, GetDesktopWindow(),
		NULL, hInstance, NULL );
	if( g_hWnd == NULL )
	{
		DWORD Error = GetLastError();
		char ErrorBuffer[ 1024 ];
		wsprintf( ErrorBuffer, "Error creating window. Error code, decimal %d, hexadecimal %X.", Error, Error );
		MessageBox( NULL, ErrorBuffer, "Error", MB_ICONHAND );
	}
}


Do take note that I indeed did receive an error. g_hWnd turned out to be null. The error message prints that the error that occured is 1407 in decimal and 57F in hex. I searched both in winuser.h, but neither returned any results at all - no occurence. Perhaps the error codes are defined elsewhere? Does anybody know why my CreateWindowEx() fails?

Share this post


Link to post
Share on other sites
I think you may be forgetting to actually Register your window class. Your setting up the WNDCLASSEX struct, but you never call RegisterClassEx(). Try adding that in and see if it works.

Share this post


Link to post
Share on other sites
Quote:
Original post by v0dKA
Do take note that I indeed did receive an error. g_hWnd turned out to be null. The error message prints that the error that occured is 1407 in decimal and 57F in hex. I searched both in winuser.h, but neither returned any results at all - no occurence. Perhaps the error codes are defined elsewhere?

Yes, here or in winerror.h.

Share this post


Link to post
Share on other sites
Quote:

I think you may be forgetting to actually Register your window class. Your setting up the WNDCLASSEX struct, but you never call RegisterClassEx(). Try adding that in and see if it works.


[wow]

I can't find an emoticon strong enough to adequately express the stupidity of my mistake. I bow to you as I pray no one else sees this thread.

Share this post


Link to post
Share on other sites
Ratterbox is right. Error code 1407 is ERROR_CANNOT_FIND_WND_CLASS. I'm sure you can guess what that means in English :P

If you're using MSVC, you can use Error Lookup in the tools menu to get an error code. Or you can use FormatMessage() to convert an error code to a string inside your app.

EDIT: Too late :P

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Ratterbox is right. Error code 1407 is ERROR_CANNOT_FIND_WND_CLASS. I'm sure you can guess what that means in English :P

If you're using MSVC, you can use Error Lookup in the tools menu to get an error code. Or you can use FormatMessage() to convert an error code to a string inside your app.

EDIT: Too late :P


Wow, thanks, I never even knew either of those existed! I'd rate you up again, but apparently you helped me recently before this.

Share this post


Link to post
Share on other sites

This topic is 4688 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this