c++winapiatlhwndmessage-map

How to determine the HWND in an ATL message map with contained windows


Let's say you're creating an ATL CWindowImpl class with one or more CContainedWindows. And then let's say you want to chain some of the CContainedWindows' ALT_MSG_MAPs so that a couple windows share some base functionality in their window procedures. But during those shared procedures, you're gonna want to know which window is receiving a given message. ATL doesn't pass HWNDs in its message map handler functions. So is there another way to determine which HWND you're dealing with?


Solution

  • Actually, I'm not sure yet, but I think this might work:

    #define MESSAGE_HANDLER_EX(msg, func) \
        if(uMsg == msg) \
        { \
            bHandled = TRUE; \
            lResult = func(hWnd, uMsg, wParam, lParam, bHandled); \
            if(bHandled) \
                return TRUE; \
        }
    

    And then the handler function should have a signature like: LRESULT HandlerFunc(HWND, UINT, WPARAM, LPARAM, BOOL&).