• Advertisement

Archived

This topic is now archived and is closed to further replies.

Help me with WinClass header, please

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

Share this post


Link to post
Share on other sites
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()).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement