Making WindowProc part of a window wrapper class without using static
I''m making a window wrapper class and it all works fine, except that I have make the windowproc function either extern or static inside the class. I want it to be non-static, but part of the class (it''ll be virtual later on) is there a(n) (easy) way to archieve this? I''ve seen a few articles on window wrappers, but they either use the way described above or they have some weird code I really don''t understand. Someone told me to declare the windowproc like this inside the class:
class CWindow
{
public:
WNDPROC WindowProc;
};
is this the way to do it? But like this, it seems like a variable to me. How do I use it? How do I set it up make it virtual etc. please help me on this it''s been bugging me for (too) long now... Thanks in advance
| Panorama 3D Engine | Contact me |
| MSDN | Google | SourceForge |
make it static and call another virtual function which can be overidden
[edited by - petewood on March 18, 2003 9:20:14 AM]
[edited by - petewood on March 18, 2003 9:20:14 AM]
if you make it static and call a virtual method from that you need a mechanism for the static method to get hold of the instance of your window class - eg a global var or something similar.
Well that''s what I want to avoid
| Panorama 3D Engine | Contact me |
| MSDN | Google | SourceForge |
| Panorama 3D Engine | Contact me |
| MSDN | Google | SourceForge |
I looked into this a bit a while ago. I''m no Windows GUI developer - so it''s not something I know much about. However you are basically trying to wrap a C API (or subset of one) in a C++ OO framework. Win32 defines the function as C linkage - so you can''t get round the fact that it has to be a static function. You also can''t get round the fact that a static function, by its nature, will have no ''this'' pointer - so you have to work around it - by either making the class a singleton or having a global var. You can use macros to tidy it up a little tho.
I''d be interested in any other (nicer) solutions to this too.
I''d be interested in any other (nicer) solutions to this too.
I ran into the same problem. What I did was leave the WindowProc function static. I created a structure to hold the windows message parameters
struct MESSAGE
{HWND hWnd;UINT uiMsg;WPARAM wParam;LPARAM lParam;}
I fill out an instance of this variable in the Base Class WindowProc function. I then handled the last message stored in a derived class WindowProc function, every frame.
Maybe not quite what you are looking for but it works all right.
I should probably be working now...
struct MESSAGE
{HWND hWnd;UINT uiMsg;WPARAM wParam;LPARAM lParam;}
I fill out an instance of this variable in the Base Class WindowProc function. I then handled the last message stored in a derived class WindowProc function, every frame.
Maybe not quite what you are looking for but it works all right.
I should probably be working now...
because then I would somehow need to get a hold of the window class pointer, and I have no idea how...
| Panorama 3D Engine | Contact me |
| MSDN | Google | SourceForge |
| Panorama 3D Engine | Contact me |
| MSDN | Google | SourceForge |
quote:Original post by Subotron
I want it to be non-static, but part of the class
You can''t. Sorry.
Here''s a good workaround.
quote:Original post by LNK2001
Here''s a good workaround.
I''ve seen that one but don''t get it :D
| Panorama 3D Engine | Contact me |
| MSDN | Google | SourceForge |
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement