Sign in to follow this  

Wndproc, getting rid of a global.

This topic is 3601 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 did post this on the end of a previous discussion of mine but i think it got lost in the ether. I'm reading through the early chapters of Intro To 3D Game Programming by Frank D. Luna. In the source code he takes a global reference of the main application for convenience and i got into a discussion about how this could be substituted by smartly passing some references around. But for the wndproc callback, what’s a good OO way to get rid of the global in this instance.
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Don't start processing messages until the application has been created.
if( gd3dApp != 0 )
return gd3dApp->msgProc(msg, wParam, lParam);
else
return DefWindowProc(hwnd, msg, wParam, lParam);
}

I feel like the answer is staring me in the face but i can't quite get it. Help much appreciated. [Edited by - JimmyDeemo on February 8, 2008 2:49:25 AM]

Share this post


Link to post
Share on other sites
So something like this;


//Where i create my app
HelloD3DApp myapp = new HelloD3DApp( /*params*/ );
SetWindowLongPtr( myapp->GetWndHnd(), GWLP_USERDATA, myapp->msgProc );



Then i can use GetWindoLongPtr() in MainWndProc to get the right one. Is that the usage you were implying?

Share this post


Link to post
Share on other sites

This topic is 3601 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this