Jump to content
  • Advertisement
Sign in to follow this  
chadsxe

Is it possible to access a class object not local to windows message proc?

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

Is it possible to access a class object that is not local to the WindowProc? For example...
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	switch( msg )
	{
	case WM_PAINT:
		//I need to be able to access this when WM_PAINT is called
		b.Render(); // Obviously this does not work
		ValidateRect( hWnd, NULL );
		return 0;
	}
	return DefWindowProc( hWnd, msg, wParam, lParam );
}

class B
{
	public:
		void Render();
};

class A
{
	public:
		B b;
};

Obviously this does not work but I was wondering what is the best way to get access to the B object when WM_PAINT is called? Regards Chad

Share this post


Link to post
Share on other sites
Advertisement
I'd use

SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)&instanceOfB);


In your window initialization method somewhere.

And then you can use:

B * instanceOfB = (B *)GetWindowLongPtr(hWnd, GWLP_USERDATA);


Inside the WndProc function.

Share this post


Link to post
Share on other sites
as long as b is global it would work wouldn't it?

oh wait b is inside a class

you would have to have a.b.Render();

and a would have to be global

although you'd probably want to put it in a namespace

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.

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!