0

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?

  • It would be available as `m_hWnd` I think? – Jonathan Potter Aug 23 '20 at 21:11
  • But wouldn't `m_hWnd` belong to the main class (the one deriving from `CWindowImpl`)? –  Aug 23 '20 at 21:13
  • I don't know for sure (not really an MFC expert) but I would have expected that the message handler would be called on the context of the window that received the message. Should be easy to verify anyway. – Jonathan Potter Aug 23 '20 at 21:23
  • I believe you are meant to have different handlers in different alternative maps, so each handler just knows which window it's for. There doesn't appear to be any way to determine which map dispatched to a given handler. If you want two or more windows with the same behavior, implement a proper `CWindowImpl`-derived class for them, with its own message map. – Igor Tandetnik Aug 23 '20 at 22:51

1 Answers1

0

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&).