I've read the documentation, which says:
ATL supports alternate message maps, declared with the
ALT_MSG_MAP
macro.
Each alternate message map is identified by a unique number, which you pass toALT_MSG_MAP
.
Using alternate message maps, you can handle the messages of multiple windows in one map.
Note that by default,CWindowImpl
does not use alternate message maps.
To add this support, override theWindowProc
method in yourCWindowImpl
-derived class and callProcessWindowMessage
with the message map identifier.
And when I look at WTL, I see message maps like:
BEGIN_MSG_MAP(CCommandBarCtrlImpl)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_FORWARDMSG, OnForwardMsg)
...
ALT_MSG_MAP(1) // Parent window messages
MESSAGE_HANDLER(WM_INITMENUPOPUP, OnParentInitMenuPopup)
...
ALT_MSG_MAP(2) // MDI client window messages
// Use CMDICommandBarCtrl for MDI support
ALT_MSG_MAP(3) // Message hook messages
MESSAGE_HANDLER(WM_MOUSEMOVE, OnHookMouseMove)
...
END_MSG_MAP()
However, I don't understand:
How they get called. (How does the code know about the existence of the alternate message maps?)
How they differ from default message maps. They all look like they're handling the same kinds of messages for the same windows...
Why they are useful. (Aren't they all for the same window anyway?)
Does anyone have a better explanation for what alternate message maps do?
(A motivation for why they were invented would be very helpful.)