Help me with WinClass header, please

Started by
1 comment, last by Zeraan 21 years, 10 months ago
I want to make a struct that have everything for a wndclass so I don''t have to type them over and over again. I made a header file with the struct, and .cpp file with code, but when I try to compile it, it said: c:\c++\beyaan\winclass.cpp(13) : error C2440: ''='' : cannot convert from ''long (__stdcall TWinClass::*)(struct HWND__ *,unsigned int,unsigned int,long)'' to ''long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'' There is no context in which this conversion is possible the line for this error is: W_Class.lpfnWndProc = TheWindowProc; //window procedure and the W_Class is in this struct: struct TWinClass { void CreateClass(HINSTANCE); void Display(int,int,char*,int); LRESULT CALLBACK TheWindowProc ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam ); WNDCLASSEX W_Class; HWND hWnd; HINSTANCE hInstance; }; Seems like I can''t do window proc inside a struct? Help me with this, please. ----------------------------- To debug, or not to debug, that is the question. Whether ''tis nobler in the computer to suffer The slings and arrows of outrageous errors, or to take C++ reference books against a sea of bugs, and by opposing, debug them.
Advertisement
Sorry, you can''t have a windowproc in a class. Unless it''s static.

but if the function is static you won''t have access to the object.

What you can do is to send a pointer to the object as the lParam(the last param in CreateWindow()).

Ok I fixed the problem. Thanks so much! Now I can just happily include winclass header and type in Create and Display without dealing with all those "details."

-----------------------------
To debug, or not to debug, that is the question.
Whether ''tis nobler in the computer to suffer
The slings and arrows of outrageous errors,
or to take C++ reference books against a sea of bugs,
and by opposing, debug them.

This topic is closed to new replies.

Advertisement