Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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

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


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
Posted
Updated 7-Oct-14 18:36pm
v3
Comments
Sergey Alexandrovich Kryukov 7-Oct-14 12:56pm    
The question is not what window is deactivated, the question is which one activates. The root cause should be there.
—SA
prasanth_mv 8-Oct-14 0:45am    
Hi Sergey Alexandrovich Kryukov,
Thank you for the comments. Today, i updated the question a little bit. The issue which i mentioned is application window loses focus and goes as back ground window after closing propertysheet (modeless).

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900