Jump to content
  • Advertisement
Sign in to follow this  
rayli1107

Problem with WndProc

This topic is 4750 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'm trying to write a wrapper class for creating generalized window. I was trying to have WndProc as a member function of the class, and then assign WndProc like this: void GLWindow::CreateWindow() { ... WNDCLASS WC; WC.lpfnWndProc = (WNDPROC) (this->WndProc); ... } where WndProc is a member function of GLWindow class However this gave me cast error, saying it cannot cast it that specific type. Can anyone tell me how I can do this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You cannot do this. This is because when you fill WNDCLASSEX it expects a simple function pointer to MsgProc. The function pointer to the MsgProc you supply is Class::Function(). Also note this is un castable (in my experience).

I wrote a wrapper for the window creation years ago and the way i did it was to just have this MsgProc floating arounf in the cpp file. I wasn't and am still not satisfied with this.

E

ace

Share this post


Link to post
Share on other sites
Why not using a static function ? Look at this :

When you create your window with CreateWindowEx() set lpParam to 'this'. You'll then be able to get it back in your static function.

//
//
//
class cWindow
{
public:
.....
private:
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
}


//
//
//
LRESULT CALLBACK cWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Get back our 'this'
cWindow* pThis = (cWindow*)GetWindowLong(hWnd, GWL_USERDATA);


switch (uMsg)
{
// Window creation
case WM_CREATE:
{
// class pointer
pThis = (cWindow*)((LPCREATESTRUCT)lParam)->lpCreateParams;

// Store it in the window's info
SetWindowLong(hWnd, GWL_USERDATA, (LONG )pThis);
}
break;

......
}

Hope it'll help you..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!