当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - How can I set focus to a modal window from a disabled non-parent window in MFC?

问题描述:

I have an application with multiple windows. When one window opens a modal dialog, the parent window automatically gets disabled by DoModal. I also disable the other windows with a call to EnableWindow(FALSE). However, if the parent window gets obscured by another application, and a user clicks on one of the other windows, I would like to give focus to the modal dialog. Is this possible to do? If so, how would I do it? I am attempting to give the user a visual clue that the application has not hung. Thanks in advance.

网友答案:

Well, when you disable a window, you prevent the user from interacting with it. So, if you disable all the windows except the modal dialog, you will not be able to click on them. I think maybe the only chance you have is to install a HookProc for the mouse and try to intercept clicks that way. I have no idea if it would work, but it is a thought.

网友答案:

Looks like I found the solution to my question. Implementing OnMouseActivate, PreTranslateMessage, and OnActivate in my main window fixes the problem, like so...

int CCVMDIChild::OnMouseActivate(CWnd* desktopWindow, UINT hitTest, UINT message)
{
    if (m_IsDisabled)
    {
        CWnd* inDialogWindow = GetAppData()->GetInDialogWindow(); // Pointer to the parent of the modal dialog
        if (inDialogWindow != nullptr)
        {
            inDialogWindow->GetLastActivePopup()->SetFocus();
            inDialogWindow->GetLastActivePopup()->FlashWindowEx(FLASHW_CAPTION, 5, 50);
        }
        return MA_NOACTIVATE;
    }
    return CDocFrame::OnMouseActivate(desktopWindow, hitTest, message);
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: