Skip to content

Instantly share code, notes, and snippets.

@Fahrni
Last active May 28, 2016 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fahrni/4ce26f04e831513b830574da00ce6ef2 to your computer and use it in GitHub Desktop.
Save Fahrni/4ce26f04e831513b830574da00ce6ef2 to your computer and use it in GitHub Desktop.
ACL Library Message Dispatch Mechanism
LRESULT ACLWinBase::DispatchMessage
(
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam
)
{
LRESULT lResult(1);
UINT uSubMsg(WM_NULL); // By default this really isn't looked at.
// If we've received a W_COMMAND message or a
// W_NOTIFY message the dive into the sub-messages
// contained in these messages.
//
switch (uMsg)
{
case WM_COMMAND:
{
uSubMsg = LOWORD(wParam);
break;
}
case WM_NOTIFY:
{
LPNMHDR pHDR = (LPNMHDR)lParam;
if (pHDR)
{
// This is the REAL message.
//
uSubMsg = pHDR->code;
}
break;
}
case WM_SYSCOMMAND:
{
uSubMsg = (UINT)wParam;
break;
}
} // Pre-message processing.
bool bail(false);
PWINMSGHNDLR pHandler = NULL;
// Check the Message map for the object, if the message passed
// in here matches one in the map then grab the name of the
// dispatch function and dispatch it!
//
for (ACLWinMessageMapCollection::iterator it = _msgMap.begin();
it != _msgMap.end() && false == bail;
++it)
{
// If the main command(wMsg) and the control ID(uSubMsg)
// match then we've found a command handler for the
// message.
//
if ((uMsg == (*it).uMsg) &&
(uSubMsg == (*it).uSubMsg))
{
pHandler = (*it).pMsgHandler;
bail = true;
}
}
// If we found a matching message handler, then
// dispatch it otherwise return false.
//
if (pHandler)
{
lResult = (this->*pHandler)(wParam, lParam);
}
return lResult;
} // ::DispatchMessage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment