Windows startup

Started by
10 comments, last by LongInteger 18 years, 2 months ago
Hi i have just started with windows programming and ive been looking at the sites and following my books and i cant work out why this aint working . . this is the error error C2440: '=' : cannot convert from 'LRESULT (__stdcall CWindows::* )(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC' this is the code

LRESULT APIENTRY CWindows::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_DESTROY:
			PostQuitMessage( 0 );
			return 0;
		case WM_PAINT:
			return 0;
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);

}

bool CWindows::Create(HINSTANCE hInstance)
{
	WNDCLASSEX wc;

	wc.cbSize         = sizeof(WNDCLASSEX);
	wc.style          = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc    = WndProc;
	wc.cbClsExtra     = 0;
	wc.cbWndExtra     = 0;
	wc.hInstance      = hInstance;
	wc.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);
	wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName   = NULL;
	wc.lpszClassName  = "D3D";

	RegisterClassEx(&wc);

	m_hWnd = CreateWindow("D3D", "D3D", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
		GetDesktopWindow(), NULL, wc.hInstance, NULL);

	ShowWindow(m_hWnd, SW_SHOWDEFAULT);
	UpdateWindow(m_hWnd);

	while(m_mMsg.message != WM_QUIT)
	{
		if(PeekMessage(&m_mMsg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&m_mMsg);
			DispatchMessage(&m_mMsg);
		}
		else
			Run();
	}

	return true;
}


i suppose my question is what is that error and how do i solve it and make sure that it doesnt happen again
Advertisement
I'm sure someone will explain better than i the **why** but you need to make the

CWindows::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

static.

Hopefully this will get you on track quicker - as I'm pressed for time and cant elaborate as much as I'd like to.

Hope this helps tho ;)

N
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
Take this example..

class TestClass{    void TestClassFunc(int);};void TestFunc(int);//...int main(){    //Call TestFunc()    TestFunc(10);    //Call TestClassFunc()    TestClass tc;    tc.TestClassFunc(10);};


At first it might seem that TestFunc() and TestClassFunc() both have the same footprint - they both return void and accept a single int parameter - but also note that you cannot call TestClassFunc() without a TestClass object to call it on. This is where the function footprint differs and the reason why a function pointer cannot point to both TestFunc() and TestClassFunc() - the footprint for TestClassFunc() is "void TestClass::TestClassFunc(int)" versus the footprint for TestFunc "void TestFunc(int)".

Making TestClassFunc() static removes the need for a TestClass object to call the function on and therefore reduces the footprint to the same as TestFunc. The downside of this is that TestClassFunc() cannot access any non static members of TestClass.
Progress is born from the opportunity to make mistakes.

My prize winning Connect 4 AI looks one move ahead, can you beat it? @nickstadb
Quote:Original post by InsaneBoarder234
Take this example..

*** Source Snippet Removed ***

At first it might seem that TestFunc() and TestClassFunc() both have the same footprint - they both return void and accept a single int parameter - but also note that you cannot call TestClassFunc() without a TestClass object to call it on. This is where the function footprint differs and the reason why a function pointer cannot point to both TestFunc() and TestClassFunc() - the footprint for TestClassFunc() is "void TestClass::TestClassFunc(int)" versus the footprint for TestFunc "void TestFunc(int)".

Making TestClassFunc() static removes the need for a TestClass object to call the function on and therefore reduces the footprint to the same as TestFunc. The downside of this is that TestClassFunc() cannot access any non static members of TestClass.


(Bold) It can't? But... I had a static instance of my CApp::Engine class that was modified by each CApp::Engine::Engine()...

Too clear that up, TestClassFunc may look along the lines of:
void TestClass::TestClassFunc(TestClass *this, int);

Notice the 'this' pointer?
A static member function can only access static members of the class because it isn't called on an object of that class. Another example..

class TestClass{    static void TestFunc();    void TestFunc2();};//...int main(){    //Call TestFunc()    TestClass::TestFunc();    //Call TestFunc2 in the same way    TestClass::TestFunc2(); //Causes an error because TestFunc2() is not static                            //and there is no TestClass object to call it on}


[edit]
Quote:I had a static instance of my CApp::Engine class that was modified by each CApp::Engine::Engine()...


You say a static instance of CApp::Engine, I was talking about a static member function.
Progress is born from the opportunity to make mistakes.

My prize winning Connect 4 AI looks one move ahead, can you beat it? @nickstadb
man some crazy stuff, to the first poster, yes i have seen the wnd proc static, my program will later derive a window from this class for D3D. Ill have another mess around . Thanks
Quote:Original post by InsaneBoarder234
A static member function can only access static members of the class because it isn't called on an object of that class. Another example..

*** Source Snippet Removed ***

[edit]
Quote:I had a static instance of my CApp::Engine class that was modified by each CApp::Engine::Engine()...


You say a static instance of CApp::Engine, I was talking about a static member function.


Oh, sorry. I misread your post. In this case this is 100% correct as there is no "this" parameter passed in.
the progrm comiles but i see no window, anyone care to troubleshoot for me, ive tried a few things and cant see why im not getting a window : /

#include ".\windows.h"CWindows::CWindows(void){}CWindows::~CWindows(void){}LRESULT APIENTRY CWindows::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){	switch(msg)	{		case WM_DESTROY:			PostQuitMessage( 0 );			return 0;		case WM_PAINT:			return 0;	}	return DefWindowProc(hWnd, msg, wParam, lParam);}bool CWindows::Create(HINSTANCE hInstance){	WNDCLASSEX wc;	wc.cbSize         = sizeof(wc);	wc.style          = WS_OVERLAPPEDWINDOW | WS_VISIBLE;	wc.lpfnWndProc    = WndProc;	wc.cbClsExtra     = 0;	wc.cbWndExtra     = 0;	wc.hInstance      = hInstance;	wc.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);	wc.hCursor        = LoadCursor(NULL, IDC_ARROW);	wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);	wc.lpszMenuName   = NULL;	wc.lpszClassName  = "D3D";	if(!RegisterClassEx(&wc))	{		MessageBox(m_hWnd, "ERROR", "REGISTER", MB_OK);		return false;	}	m_hWnd = CreateWindow("D3D", "D3D", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,		GetDesktopWindow(), NULL, wc.hInstance, NULL);	if(FAILED(m_hWnd))	return false;	ShowWindow(m_hWnd, SW_SHOWDEFAULT);	UpdateWindow(m_hWnd);	return true;}void CWindows::Run(){}WPARAM CWindows::MessageLoop(){	while(m_mMsg.message != WM_QUIT)	{		if(PeekMessage(&m_mMsg, NULL, 0, 0, PM_REMOVE))		{			TranslateMessage(&m_mMsg);			DispatchMessage(&m_mMsg);		}		else			Run();	}		return m_mMsg.wParam; }//the main is#include "Windows.h"int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int){	CWindows Window;	Window.Create(hInstance);	Window.MessageLoop();	return 0;}


the window is being created just not seen on screen cos i have to go into system props and delete the process if i want to compile and try to run again
Unless I'm missing something here, I don't see anything specific to DirectX in this thread [smile]

I'll push this back to FB - I think you'll get better (or continued) support for your problem over there..

Cheers,
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

i placed it in game programming to begin with, it got moved here, this window when i see it working will be overtaken with a d3d window and this will be the d3d base class . . first i must get the base window working.

This topic is closed to new replies.

Advertisement