Home Dashboard Directory Help
Search

MFC - CDialogEx - Deactivating and activating dialog set focus to first dialog item instead to last focused item by Jan Minarik


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 672452
Opened: 6/2/2011 5:21:02 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
2
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Deactivating and activating dialog window based on CDialogEx class set focus to first dialog item instead of last focused item before dialog lost focus. This will happen only in CDialogEx. Dialogs based on CDialog works fine.
Details
Sign in to post a comment.
Posted by Microsoft on 6/17/2011 at 2:13 PM
Hello Jan,

Thanks for the report. This issue has been fixed in MFC for the next major release of Visual Studio.

Pat Brenner
Visual C++ Libraries Development
Posted by MS-Moderator08 [Feedback Moderator] on 6/2/2011 at 10:37 PM
Thank you for reporting the issue.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution.These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 6/2/2011 at 5:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by rohtab on 12/15/2012 at 3:37 PM
This issue has been fixed in Visual Studio 2012. The fix is to call Default() in OnActivate

void CMyDialogEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
{
    Default();
    __super::OnActivate(nState, pWndOther, bMinimized);
}
Posted by Jan Minarik on 6/2/2011 at 5:24 AM
1) Inherite CDialogEx to own class and create one protected member CWnd *m_wndLastFocused;
2) In constructor set m_wndLastFocused(NULL)
2) override OnActivate and place code:
void CMyDialogEx::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
    CDialogEx::OnActivate(nState,pWndOther,bMinimized);

    if (nState == WA_INACTIVE )
        m_wndLastFocused = GetFocus();
    else if( m_wndLastFocused && IsWindow(m_wndLastFocused->m_hWnd) )
        m_wndLastFocused->SetFocus();
}

This will correct this problem.