0

Microsoft had a knowledge base article describing how to modify the message loop in at ATL .exe so that modeless dialogs can receive appropriate messages.

I was wondering how to elegantly do this if you have potentially multiple modeless dialogs, and you don't know which dialogs might exist at any given time. Like perhaps the .exe hosts several different COM classes, each with different dialogs, and who knows which one might be instantiated.

Would you create a global set of hwnds, and have each dialog class place its hwnd in the set upon creation, and then have the message loop iterate through the set calling IsDialogMessage (and TranslateAccelerator)?

2 Answers2

0

The message specifies its target (which might be a child of the actual dialog), I would handle this by having a set of dialog pointers and then simply iterate the set testing each with IsChild() and only when the right dialog HWND is found would I use IsDialogMessage.

The alternative is to walk up the ancestor tree from the HWND in the MSG translating HWNDs to objects somehow and when you get to a window that is a dialog use IsDialogMessage.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • What about just having a global hwnd representing the activate dialog? And then whenever a dialog gets activated (WM_ACTIVATE), it assigns its own hwnd to the global one. And the message loop checks the message against the activate dialog hwnd. –  Apr 26 '21 at 12:28
0

WTL's solution for this challenge is to have a specialized message loop class which registers itself in static container so that dialogs could discover message loops for the threads they belong to.

Dialogs can register themselves with these message loops via CMessageLoop::AddMessageFilter and have their callbacks invoked once it comes to translating the messages.

Example:

    // register object for message filtering and idle updates
    CMessageLoop* pLoop = _Module.GetMessageLoop();
    ATLASSERT(pLoop != NULL);
    pLoop->AddMessageFilter(this);
    pLoop->AddIdleHandler(this);
Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Cool, thanks. So does that work in conjunction with ATL's own modules and message loop, or does that replace it? –  Apr 25 '21 at 17:54
  • WTL works very well with ATL in general, but both are a bit of out of date. You might want to look into WTL samples if you're interested in WTL, or just check out their use of `CMessageLoop` to get an idea about their solution for multiple modeless dialogs. – Roman R. Apr 25 '21 at 17:56
  • Perhaps a similar idea can be achieved by implementing IInputObject and IInputObjectSite. –  Apr 26 '21 at 11:08