CreateWindow() failing

Started by
14 comments, last by mateo 18 years, 10 months ago
After trying to figure out why nothing was coming up, I debugged the program and found that my HWND variable was not being set to a memory address because CreateWindow() was not working. Here is the error I get when I click on my hWnd variable: unused CXX0030: Error: expression cannot be evaluated Here is my function call, I see nothing wrong with it: hWnd = CreateWindow("PongWindow", "PongGame", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, NULL, NULL, hInstance, NULL );
There are some things so stupid that only an intellect could believe them.
Advertisement
Make sure that RegisterClassEx() succeedes.

Sorry about the only thing i think of.

ace
Yep, you're right, it's not registering the class. I'm noticing something, the wcex.lpfnWndProc variable is not being set to the same memory address of my WindowProc() function. Is that most likely the problem?
There are some things so stupid that only an intellect could believe them.
Yes.
I tired moving the WindowProc() into the WindowsClass, but generates a conversion error:

'=' : cannot convert from 'long (__stdcall WindowsClass::*)(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,un
signed int,long)'

This is what my WindowsClass header and source files look like:

WindowsClass.h
#define WIN32_LEAN_AND_MEAN#include <windows.h>LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);class WindowsClass{public:	WindowsClass( HINSTANCE hInst );	bool initRegisterWindow();	void createWindow();	HWND getHWND(){ return hWnd; }	HINSTANCE getHINSTANCE() { return hInstance; }private:	HWND		hWnd;	HINSTANCE	hInstance;	WNDCLASSEX	wcex;};


WindowsClass.cpp
#include "WindowsClass.h"WindowsClass::WindowsClass( HINSTANCE hInst ){	hInstance = hInst;	if(	initRegisterWindow() )		createWindow();	else		createWindow();//RegisterClassEx() fails}bool WindowsClass::initRegisterWindow(){	wcex.cbSize = sizeof(wcex);	wcex.style = CS_CLASSDC;	wcex.lpfnWndProc = WindowProc;	wcex.cbClsExtra = 0L;	wcex.cbWndExtra = 0L;	wcex.hInstance = hInstance;	wcex.hIcon = NULL;	wcex.hCursor = NULL;	wcex.hbrBackground = NULL;	wcex.lpszMenuName = NULL;	wcex.lpszClassName = "GameClass";	wcex.hIcon = NULL;	if(!RegisterClassEx(&wcex))		return false;	return true;}void WindowsClass::createWindow(){	hWnd = CreateWindow("PongWindow", "PongGame", WS_OVERLAPPEDWINDOW,						 0, 0, 640, 480, NULL, NULL, hInstance, NULL );	ShowWindow(hWnd, SW_SHOWNORMAL);	UpdateWindow(hWnd);}LRESULT CALLBACK WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){	switch(uMsg)	{	case WM_DESTROY:		PostQuitMessage(0);		break;	default:		return DefWindowProc(hWnd, uMsg, wParam, lParam);	}	return 0;}


Any ideas as to why it's setting it to the wrong address?
There are some things so stupid that only an intellect could believe them.
Have a look st this and see see if it helps. winprog

    const char szClassName[ ] = "WinClass";   //Windows window class name    const char szWTitle[ ] = "WinTitle";        //Windows window Title    HWND hwnd;               /* This is the handle for our window */        WNDCLASSEX wincl;        /* Data structure for the windowclass */    /* The Window structure */    wincl.hInstance = hThisInstance;    wincl.lpszClassName = szClassName;    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */    wincl.cbSize = sizeof (WNDCLASSEX);    /* Use default icon and mouse-pointer */    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);    wincl.lpszMenuName = NULL;                 /* No menu */    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */    wincl.cbWndExtra = 0;                      /* structure or the window instance */    /* Use Windows's default color as the background of the window */    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;    /* Register the window class, and if it fails quit the program */    if (!RegisterClassEx (&wincl))        return false;    /* The class is registered, let's create the program*/    hwnd = CreateWindowEx (           0,                   /* Extended possibilites for variation */           szClassName,         /* Classname */           szWTitle,       /* Title Text */           WS_OVERLAPPEDWINDOW, /* default window */           CW_USEDEFAULT,       /* Windows decides the position */           CW_USEDEFAULT,       /* where the window ends up on the screen */           w,                 /* The programs width */           h,                 /* and height in pixels */           HWND_DESKTOP,        /* The window is a child-window to desktop */           NULL,                /* No menu */           hThisInstance,       /* Program Instance handler */           NULL                 /* No Window Creation data */           );    /* Make the window visible on the screen */     ShowWindow (hwnd, nCmdShow); 

Chad, I read the stuff on that site about registering windows classes, but it doesn't really help me with my problem. They are doing basically the same thing I am, just setting the name of the Windows procedure function name to the correct WNDCLASSEX variable. It's so simple yet it's not working out for me. Could it be that it's declared globally in the header file, and the header file is included in the main.cpp file? I dunno, I'm stumped.
There are some things so stupid that only an intellect could believe them.
...

wcex.lpszClassName = "GameClass";

...

hWnd = CreateWindow("PongWindow", ...
Your window message handling function can not be a class member, it has to be a s typical C function.

ace
Or static method of a class.

This topic is closed to new replies.

Advertisement