Window in a Class
Greetings!
I would like to get my window stuff into a single class, for example:
class CMyWindow
{
public:
virtual void Create();
virutal void WindowProc();
virtual void Destroy();
};
How to Register "WindowProc" when calling CreateDialog(... WindowProc()) ?
Any ideas?
the problem is that the winproc has to be a static function. You cant pass in a class member as the message handler. You can however keep pointers to your window class and call the winproc member function from within the static message handler.
Quote:Original post by IFooBar
the problem is that the winproc has to be a static function. You cant pass in a class member as the message handler. You can however keep pointers to your window class and call the winproc member function from within the static message handler.
Thats how I do it too. Just use a global variable for your window (or something list-like if you have more windows to handle) and call the appropriate message handler member function from your window class from the static (and global)WndProc function.
For this purpose, each window has properties which you can set to any value you wish using Get/SetProp(), e.g. the window class' this pointer. You also have the option of using the slightly faster Get/SetWindowLong(GWL_USERDATA, ...), however this might conflict with other libraries (like MFC) using this data member of a window.
-Markus-
-Markus-
Let me show you a bit ...
This is my temporary window class, how you do it is up to you.
1. I have a MsgCenter class that all messages is sent to (not recommended, but I am experimenting with it), that is the m_MsgCenter object.
2. I can ONLY create 1 and only 1 object of this class. a small change is needed to make it create more (simple change).
3. I use a small struct to initialize the window ...
mmmm.... was thinking of posting a simple .cpp code to just show the implementation, but the code is big, and awfull
But basically, just sett the sThis correctly, and the rest should be ok ...
I must clean up my code first, and improve a few small things before I can post this base class.
Once you have the this base class ready, you just inherit this object into your GDI, DX or OpenGl object to make a window object. It is not 100% DX friendly yet, but give me some time.
This is my temporary window class, how you do it is up to you.
1. I have a MsgCenter class that all messages is sent to (not recommended, but I am experimenting with it), that is the m_MsgCenter object.
2. I can ONLY create 1 and only 1 object of this class. a small change is needed to make it create more (simple change).
3. I use a small struct to initialize the window ...
#ifndef WNDBASE_H#define WNDBASE_H#include "help.h"#include "msgcenter.h"#include "logg.h"struct WndType{ LPCTSTR title; int width; int height; bool fullscreen; DWORD exstyle; DWORD style;};class WndBase{ public: WndBase( HINSTANCE hInstance, WndType type, Logg *logg ); virtual ~WndBase(); virtual int CreateWnd(); // creates a window based on WndType virtual int Initialize(); // not in use at the moment virtual int Draw() = 0; // pure virtual?? virtual int Destroy(); // does cleanup void Show( bool show ); // show/hide a window void ShowMouse( bool show ); // show/hide cursor MsgCenter* GetMsgCenter(); // return the m_pMsgCenter protected: HINSTANCE m_hInstance; // Holds The Instance Of The Application HDC m_hDC; // Private GDI Device Context HWND m_hWnd; // Holds Our Window Handle MSG m_uMsg; // message variable DWORD m_dwExStyle; // Window Extended Style DWORD m_dwStyle; // Window Style RECT m_ScreenRect; // Grabs Rectangle Upper Left / Lower Right Values RECT m_ClientRect; // Rect of client area bool m_fullscreen; // fullscreen? bool m_active; MsgCenter *m_pMsgCenter; Logg *m_pLogg; LPCTSTR m_sCName; WndType m_WndType; private: static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); LRESULT MessageProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); static WndBase *sThis;};#endif
mmmm.... was thinking of posting a simple .cpp code to just show the implementation, but the code is big, and awfull
But basically, just sett the sThis correctly, and the rest should be ok ...
I must clean up my code first, and improve a few small things before I can post this base class.
Once you have the this base class ready, you just inherit this object into your GDI, DX or OpenGl object to make a window object. It is not 100% DX friendly yet, but give me some time.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement