Search

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

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)
0
User(s) can reproduce this bug
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 (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010 SP1

Steps to reproduce

1) Create C++ MFC project, DIalog based application and finish the wizzard. New dialog based application based on CDialogEx will be created.
2) In resource view modify the dialog and place two Edit Controls from Toolbox onto dialog.
3) Modify tab order for dialog items (Ctrl+D) and set order as: Edit1->Edit2->Ok->Cancel.
4) Compile and run the project - Dialog application will show up.
5) Enter any text into Edit1 and Edit2, then set the cursor few characters back from end in Edit2. Focus is now at Edit2 and cursor is in position few chars back from the end of the text entered in Edit2.
6) Switch to another application in windows (Alt+Tab), and back to Dialog App.
7) Focus is set in Edit1 and all text in Edit1 is selected. Cursor position and focus to Edit2 is lost.

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

After switching to another windows application and back to the Dialog application, focus is set to the first-order dialog control item instead of remain on last focused item before Dailog lost focus.

Expected results

After switching to another application and back to the Dialog, focus must stay on last focused dialog control and if it was Edit control, the curor position must remain on last position (like CDialog does).
File Attachments
0 attachments
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.