Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

c++ MsgProc, how to make class that allows extra message capturing to be added?

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

Hi, I want to make a class to use for window apps. E.g. handles all the basics of window creation and running. The only problem I have encountered, since I am putting the MsgProc inside the class, I need to be able to still check if the messages received can be routed or something. Like whenever a message is sent to the MsgProc, the MsgProc calls a function in the same class that calls another function with all the message values from the msgproc. Anyone know how to implement that? As I am having problems with the static not being able to read the non-static. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Hmm, here's a little proof of concept. .NET-style windowing:


typedef void (*ResizeHandler)(int width, int height);
typedef void (*MoveHandler)(int x, int y);

class Window
{
public:
Window() :
OnResize(0),
OnMove(0)
{
}

static WINAPI InstanceDispatch(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// either thunk, or use a table, or whatever you do
// to call the instance ptr

return instance->DispatchMessage(wnd, msg, wParam, lParam);
}

LRESULT DispatchMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// should be in order of message frequency
switch(msg)
{
case WM_PAINT:
break;

// ...
case WM_SIZE:
if(OnResize)
OnResize(HIWORD(wParam), LOWORD(wParam));

default:
return DefWindowProc(wnd, msg, wParam, lParam);
}
}

MoveHandler OnMove;
ResizeHandler OnResize;
};

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Google. Try "window procedure class wrapper".


That really was the most subtle plug I've ever seen [grin]

It's true though, that article is bang on what you'll need for this.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!