0

I have a modal dialog that shows a modeless 'companion dialog' on a button press. To make the UI more intuitive and fluid I'd like the focus to follow the mouse and move between the dialogs without requiring an extra click.

Is there a simple message handler that would help here? I think I could do it by using TrackMouseEvent and OnMouseHover in each dialog - but that seems pretty involved for such a 'simple' effect?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Kyudos
  • 625
  • 4
  • 18

1 Answers1

0

OK...so I was totally over thinking this! Just use OnMouseMove and OnNcMouseMove:

//------------------------------------------------------------------------------
void DlgA::OnMouseMove(UINT nFlags, CPoint point)
//------------------------------------------------------------------------------
{
    HWND hwnd = ::GetActiveWindow();
    if (pDlgB != NULL)
    {
        if (hwnd == pDlgB->GetSafeHwnd())
        {
            // Make the focus switch automatically
            SetFocus();
        }
    }
}
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Kyudos
  • 625
  • 4
  • 18
  • 1
    [How to set focus in a dialog box](https://devblogs.microsoft.com/oldnewthing/20040802-00/?p=38283). – IInspectable Sep 18 '20 at 14:09
  • Though, even when done properly, this will start a taskbar flash blizzard if you ever decide to switch to a different thread, e.g. a different application's window. – IInspectable Sep 18 '20 at 14:11
  • @IInspectable - I don't see why it would? It only switches focus from one to the other if one (or other) already has the focus. If the focus is elsewhere, it won't do anything. – Kyudos Sep 20 '20 at 23:15