父窗口失去焦点并成为后台

父窗口失去焦点并成为后台

本文介绍了关闭Propertysheet后,父窗口失去焦点并成为后台。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个测试MDI应用程序(在VS2012中开发的MFC应用程序),它在文件菜单点击时创建一个CPropertySheet对话框(无模式)。该属性表包含两个CPropertyPages。在一个属性页面中,我弹出一个模态对话框,在该页面中单击按钮。在关闭了propertysheet(在关闭模式对话框之后)之后,它出现了一个问题,即我的主应用程序窗口(框架窗口)失去焦点并且它会回到地面。另一个应用程序窗口位于我的应用程序后面,作为前景窗口。提到的问题只会发生,如果从properypage启动模态对话框,否则没有问题



请注意,我创建了正确的工作表作为如下:



pSheet->创建(AfxGetMainWnd(),WS_SYSMENU | WS_MINIMIZEBOX | WS_OVERLAPPED | WS_CAPTION | DS_MODALFRAME | WS_VISIBLE);





我找到了一个解决问题的方法,通过在我的课程中处理WM_DESTROY来解决问题,该课程源自CProperySheet,如下所示:



Hi All,

I have an test MDI application (MFC app developed in VS2012) which create a CPropertySheet dialog (modeless) up on a file menu click. The propertysheet contains two CPropertyPages. In one property page, i am popping-up a Modal dialog, up on a button click in that page. And after the closing of propertysheet (after closing modal dialog), it got with an issue that my main application window (frame window) loses focus and it goes to back ground. And another application windows which was in back of my application, came as foreground window. The mentioned issue is only happening, if modal dialog is launched from properypage, otherwise no issues.

Please note that, i created properysheet as follows:

pSheet->Create(AfxGetMainWnd(), WS_SYSMENU|WS_MINIMIZEBOX|WS_OVERLAPPED|WS_CAPTION|DS_MODALFRAME|WS_VISIBLE);


I found a work around to fix the the issue by handling WM_DESTROY in my class which is derived from CProperySheet as follows:

void CMyProperySheet::OnDestroy()
{
    CPropertySheet::OnDestroy();

    ::SetForegroundWindow(AfxGetMainWnd()->GetSafeHwnd());//Work around
}





修复主要应用程序问题的工作转到后台。我想知道是什么原因导致主应用程序窗口失去焦点并进入后台。如果您有任何想法,请分享。



谢谢,

Prasanth



The work around fixed the issue of main application goes to background. I would like to know what causes the main application windows to lose focus and goes to the back ground. if you have any idea, please share.

Thanks,
Prasanth

推荐答案


这篇关于关闭Propertysheet后,父窗口失去焦点并成为后台。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:32