关闭Propertysheet后,父窗口失去焦点并成为后台。 [英] Parent window loses focus and become background after closing Propertysheet.

查看:163
本文介绍了关闭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

推荐答案

嗨朋友,



我可以通过使用窗口样式WS_POPUP而不是WS_OVERLAPPED解决问题。



我想得出结论,要解决这个问题:要么我们可以在propertiesysheet类的WM_DESTROY处理程序中使用:: SetForegroundWindow,要么使用上面提到的窗口样式。



问候,

Prasanth
Hi Friends,

I could solve the issue by using the window style WS_POPUP instead of WS_OVERLAPPED.

I would like conclude that to fix the issue: either we can have work around of using ::SetForegroundWindow in the WM_DESTROY handler of propertysheet class OR using the window style as mentioned above.

Regards,
Prasanth


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆