Boost logo

Boost Users :

Subject: Re: [Boost-users] Connecting Windows Messages/Events with Boostcallbacks
From: Andrew Holden (aholden_at_[hidden])
Date: 2011-03-24 10:12:40


On Thursday, March 24, 2011 8:42 AM, Igor R wrote:
>> Using your approach, I need to use a case statement inside a message
loop.
>
> As you can see, struct Handler in my example doesn't have any case
statements
> as well.
> Again: the basic, lowlevel message processing is hidden - in my
example in the
> "button" class, in smart win++ somewhere in WidgetWindow or its base
classes.
> The *users* of the framework do not need to deal with messages as the
> framework exposes higher-level facilities.

Perhaps you can replace the switch statement with a map or similar
(warning: untested):

typedef std::map <UINT, boost::signals2::signal <LRESULT (HWND, UINT,
WPARAM, LPARAM)> MessageMap;
MessageMap message_map;

LRESULT CALLBACK WindowProc(
  __in HWND hwnd,
  __in UINT uMsg,
  __in WPARAM wParam,
  __in LPARAM lParam
)
{
        MessageMap::const_iterator handler = message_map.find (uMsg);
        if (handler != message_map.end())
        {
                return handler->second (hwnd, uMsg, wParam, lParam);
        }
        else
        {
                return DefWindowProc (hwnd, uMsg, wParam, lParam);
        }
}

You could then insert any handler for any message into message_map. I'm
not sure what combiner would be most appropriate here. There is also
the question of where message_map should really go. A global variable
(as my example implies) probably isn't the best place.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net