C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-07-2009, 07:51 PM   #1
Math wizard
 
Join Date: Dec 2006
Location: Minot, ND, USA
Posts: 516
Window class not found - why?

Having adapted my program to using malloc instead of direct allocation, I have this strange, unexpected problem. Without even touching these Windows elements, suddenly, BitBlt stopped working (causing something to appear in the top left of my screen drawn on top of everything, making it impossible to see what I'm doing. I found the cause to be the WindowHandle being 0. Using common diagnostics, the "GetLastError" function, I see that the class is not being found. Why is this? How come, without even changing this content, it suddenly stopped working? The only change I made was that of using malloc (which works as far as I can tell) for my image data, which is irrelevent....

Code:
// Window definitions
HWND WindowHandle; // window handle
WNDCLASSEX WindowClass; // window class

// in the WinMain function, first thing
	WindowClass.cbSize = sizeof(WNDCLASSEX);
	WindowClass.style = CS_HREDRAW | CS_VREDRAW;
	WindowClass.lpfnWndProc = WndProc;
	WindowClass.cbClsExtra = 0;
	WindowClass.cbWndExtra = 0;
	WindowClass.hInstance = hInstance;
	WindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	WindowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	WindowClass.lpszMenuName = NULL;
	WindowClass.lpszClassName = "MyClass";
	WindowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
	
	// Register the window class
	if (!RegisterClassEx(&WindowClass);)
	{
		DebugTest[19] = (double)GetLastError();
		return 1;
	}
	
	WindowHandle = CreateWindowW("MyClass",
		"Platform Masters 1.0 (development version)",
		WS_OVERLAPPEDWINDOW |
		WS_VISIBLE |
		WS_SYSMENU,
		WindowPos.x, WindowPos.y,
		WindowSize.x, WindowSize.y,
		NULL,
		NULL,
		hInstance,
		NULL);
	
	DebugTest[19] = (double)GetLastError(); // returns 1407 - cannot find class
	
	if (WindowHandle == 0)
	{
		return 0;
	}
__________________
High elevation is the best elevation. The higher, the better the view!
My computer: XP Pro SP3, 3.17 GHz C2D CPU, 4 GB DDRII800 RAM (3 GB effective), X-Fi Platinum sound, GeForce 7600 GT, 1920x1440 resolution, 250 GB HDD, Visual C++ 2008 Express
ulillillia is offline   Reply With Quote
Old 05-08-2009, 08:51 AM   #2
Registered User
 
Join Date: Dec 2007
Posts: 146
The code you posted has errors.

Code:
if (!RegisterClassEx(&WindowClass);)  <<------  ; shouldn't be there 
WindowPos and WindowSize are not shown to be defined. When I placed your code in a generated hello world app, I used CW_USEDEFAULT for .x's and 0 for .y's. I also had to change the WinMain so it didn't use the InitInstance and RegisterClass functions that were generated. I also added a DWORD ret for your DebugTest[19], since it also wasn't shown to be defined. The program ran as expected. No errors, therefore the code you posted isn't the problem. (Assuming your positioning variables have valid values and the ; error above was just a typo here, not in your actual code.

Last edited by DaveH; 05-08-2009 at 08:54 AM.
DaveH is offline   Reply With Quote
Old 05-10-2009, 01:06 AM   #3
tjb
Registered User
 
Join Date: Jan 2009
Posts: 31
You're calling CreateWindowW, not CreateWindowA, so your class name parameter should be L"MyClass" (note the L prefix), not "MyClass". Also, although it may not be an issue depending on exactly how you're compiling the file, your "MyClass" in the context of WindowClass.lpszClassName = "MyClass" really should be _T("MyClass") (which expands to "MyClass" or L"MyClass", depending on the UNICODE preprocessor definition).

Read up on CreateWindow. Any literal parameter that is LPTSTR or LPCTSTR should be written as "XXXX" if calling CreateWindowA, L"XXXX" if calling CreateWindowW, or _T("XXXX") if calling CreateWindow (which is just defined to be CreateWindowA or CreateWindowW, depending on UNICODE and/or _UNICODE).

Last edited by tjb; 05-10-2009 at 01:09 AM.
tjb is offline   Reply With Quote
Old 05-12-2009, 10:01 PM   #4
int x = *((int *) NULL);
 
Cactus_Hugger's Avatar
 
Join Date: Jul 2003
Location: Banks of the River Styx
Posts: 891
Quote:
Read up on CreateWindow. Any literal parameter that is LPTSTR or LPCTSTR should be written as "XXXX" if calling CreateWindowA, L"XXXX" if calling CreateWindowW, or _T("XXXX") if calling CreateWindow (which is just defined to be CreateWindowA or CreateWindowW, depending on UNICODE and/or _UNICODE).
You're on the right track there. But:
LPTSTR, LPCTSTR - _T("XXXX") - Found in structures, mostly.
LPSTR, LPCSTR - "XXXX" - Found in the A versions of the functions, ie, CreateWindowA
LPWSTR, LPCWSTR - L"XXXX" - Found in the W versions of the functions, ie, CreateWindowW
__________________
long time; /* know C? */
Unprecedented performance: Nothing ever ran this slow before.
Any sufficiently advanced bug is indistinguishable from a feature.
Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
The best way to accelerate an IBM is at 9.8 m/s/s.
recursion (re - cur' - zhun) n. 1. (see recursion)
Cactus_Hugger is offline   Reply With Quote
Reply

Tags
class, not found, window, wndclassex

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Message class ** Need help befor 12am tonight** TransformedBG C++ Programming 1 11-29-2006 11:03 PM
Why only 32x32? (OpenGL) [Please help] Queatrix Game Programming 2 01-23-2006 02:39 PM
Linking OpenGL in Dev-C++ linkofazeroth Game Programming 4 09-13-2005 10:17 AM
Pong is completed!!! Shamino Game Programming 11 05-26-2005 10:50 AM
OpenGL Window Morgul Game Programming 1 05-15-2005 12:34 PM


All times are GMT -6. The time now is 05:57 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22