Jump to content
  • Advertisement

Archived

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

ECKILLER

encapsulating wndproc

This topic is 6422 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

Anyone know how to put the msg proc function in a class? If i make it static then it doesnt know which window object the msg proc belongs to. ECKILLER

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You can''t
The "best" way is to make it a static function , but that''s clearly not what you want ..
however you can go the other way ,
you create a Controller class, pass it to windows, then figure out with object windows returned to you (and if it''s a derived class of Controller) and go from there
for more info check the Win32 Tutorial at: www.relisoft.com
(very nice OOP-based wrapper of Win32 w/o using MFC there )

-vat
machinshin@onebox.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Create a class for a window, and in its constructor, or wherever you call CreateWindow(), use SetWindowLong() and GWL_USERDATA to store the "this" pointer for this object. Then, keep your WndProc a global function. The first thing your WndProc will do is get the "this" ptr for the hWnd it is given with GetWindowLong(). Then call a member function of that object. In other words, don''t do your message processing from WndProc - just use WndProc to hand off to the method in the appropriate object. You could try something like this:

class CWindow {

public:
CWindow(void) {

/* Register the WNDCLASS here */

m_hWnd = CreateWindow( /* Whatever you want in here */)

SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)this);
}

virtual LRESULT wndProc(UINT uiMsg, WPARAM wParam, LPARAM lParam) {

switch(uiMsg) {

/* Message handling goes here */
}
}

protected:
HWND m_hWnd;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
CWindow * pWindow;

pWindow = (CWindow *)GetWindowLong(hWnd, GWL_USERDATA);

return pWindow->wndProc(uiMsg, wParam, lParam);
}

Share this post


Link to post
Share on other sites
Create a class for a window, and in its constructor, or wherever you call CreateWindow(), use SetWindowLong() and GWL_USERDATA to store the "this" pointer for this object. Then, keep your WndProc a global function. The first thing your WndProc will do is get the "this" ptr for the hWnd it is given with GetWindowLong(). Then call a member function of that object. In other words, don''t do your message processing from WndProc - just use WndProc to hand off to the method in the appropriate object. You could try something like this:

class CWindow {

public:
CWindow(void) {

/* Register the WNDCLASS here */

m_hWnd = CreateWindow( /* Whatever you want in here */)

SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)this);
}

virtual LRESULT wndProc(UINT uiMsg, WPARAM wParam, LPARAM lParam) {

switch(uiMsg) {

/* Message handling goes here */
}
}

protected:
HWND m_hWnd;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
CWindow * pWindow;

pWindow = (CWindow *)GetWindowLong(hWnd, GWL_USERDATA);

return pWindow->wndProc(uiMsg, wParam, lParam);
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!