Jump to content
  • Advertisement
Sign in to follow this  
JimmyDeemo

Wndproc, getting rid of a global.

This topic is 3786 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
Advertisement
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
I've got some code for this on my site in one of my (very few) articles: Link

EDIT: Bah, some of the links to MSDN pages are borked in that article. Oh well...

Share this post


Link to post
Share on other sites
Also look into SetProp and GetProp.
I've used these successfully for the things you're doing.

[Edited by - eq on February 8, 2008 9:05:20 AM]

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!