Jump to content
  • Advertisement

Archived

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

Promit

Can you make your WndProc a member function of a class?

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

Ive tried and tried and tried, but i cant get it to work. THe compiler cant cast the member function pointer to a regular function pointer, and i cant seem to help it. Any known ways to do this? ----------------------------- The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Share this post


Link to post
Share on other sites
Advertisement
Make you function static, and put a pointer to you window object somewhere. In the static function find that pointer and call the non-static window proc.

If you only have 1 window, make a static (global) variable in your module.
If you need more windows, make a map (STL) of the HWND to your pointer.

Share this post


Link to post
Share on other sites
- There is a hidden 'this' pointer passed to all member functions of a class.

- There is no way for windows to pass this arguement to the window procedure. If you did manage to get windows to call a member function then A: your parameters would be in the wrong place on the stack for the member function to work with them. B: The member function couldn't access any of the member variables since it would have no idea which object to work on.


Edited by - B-Barlow on December 30, 2001 1:34:11 AM

Share this post


Link to post
Share on other sites
Yes,

In the header file:
      
private:
static LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );


In the cpp file:
  
LRESULT CALLBACK <class name>::WndProc( HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{

}


and when you register your window class:
  
wc.lpfnWndProc = (WNDPROC) WndProc;


Shabadoo

Edited by - Shabadoo on December 30, 2001 6:41:09 AM

Edited by - Shabadoo on December 30, 2001 6:43:42 AM

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!