Automatically Move Focus Between Dialogs

113 views Asked by At

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?

1

There are 1 answers

3
Kyudos On

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();
        }
    }
}