CMDIChildWnd::OnMDIActivate / CMFCTabCtrl::SetActiveTab is called more than once when adding a new tab to an MDI tabbed application that causes flickering in the tab window and application.

Locked CMDIChildWnd::OnMDIActivate / CMFCTabCtrl::SetActiveTab is called more than once when adding a new tab to an MDI tabbed application that causes flickering in the tab window and application.

  • Wednesday, September 28, 2011 10:09 AM
     
      Has Code
    Hello,

    I have a problem in my MFC MDI tabbed VS2010 application (flickering, focus, redraw performance) when adding a new MDI tabbed document (File/New) and one or more document(s) are already open. First I thought it is a problem of my application but I found out when
    I debugged into the sample VisualStudioDemo from the Visual Studio Feature Pack, that it has the same problem.
    The following output is generated when adding a new document to the demo application with already one document opened:
    Function: CMDIChildWnd::OnMDIActivate(int, CWnd *, CWnd *), 0x03ce3b98 {CChildFrame hWnd=0x000d075e} 0 0x03ce2b58 {CChildFrame hWnd=0x001c0794} 0x03cf1fe8 {CVisualStudioDemoView hWnd=0x000707f6}
    Function: CMDIChildWnd::OnMDIActivate(int, CWnd *, CWnd *), 0x03ce2b58 {CChildFrame hWnd=0x001c0794} 1 0x03ce2b58 {CChildFrame hWnd=0x001c0794} 0x03ce5f98 {CVisualStudioDemoView hWnd=0x001a073e}
    Function: CMDIChildWnd::OnMDIActivate(int, CWnd *, CWnd *), 0x03ce2b58 {CChildFrame hWnd=0x001c0794} 0 0x03ce3b98 {CChildFrame hWnd=0x000d075e} 0x03ce5f98 {CVisualStudioDemoView hWnd=0x001a073e}
    Function: CMDIChildWnd::OnMDIActivate(int, CWnd *, CWnd *), 0x03ce3b98 {CChildFrame hWnd=0x000d075e} 1 0x03ce3b98 {CChildFrame hWnd=0x000d075e} 0x03cf1fe8 {CVisualStudioDemoView hWnd=0x000707f6}
    Function: CMFCTabCtrl::SetActiveTab(int), 0x03cf4378 {CMFCTabCtrl hWnd=0x001306de} 0 0 2
    Function: CMFCTabCtrl::SetActiveTab(int), 0x03cf4378 {CMFCTabCtrl hWnd=0x001306de} 1 0 2
    Function: CMDIChildWnd::OnMDIActivate(int, CWnd *, CWnd *), 0x03ce3b98 {CChildFrame hWnd=0x000d075e} 0 0x03ce2b58 {CChildFrame hWnd=0x001c0794} 0x03cf1fe8 {CVisualStudioDemoView hWnd=0x000707f6}
    Function: CMDIChildWnd::OnMDIActivate(int, CWnd *, CWnd *), 0x03ce2b58 {CChildFrame hWnd=0x001c0794} 1 0x03ce2b58 {CChildFrame hWnd=0x001c0794} 0x03ce5f98 {CVisualStudioDemoView hWnd=0x001a073e}
    Function: CMFCTabCtrl::SetActiveTab(int), 0x03cf4378 {CMFCTabCtrl hWnd=0x001306de} 1 1 2
    

    The TRACE parameters for the functions are:

    SMFCTabCtrl::SetActiveTab: Function: $FUNCTION, {this} {iTab} {m_iActiveTab} {m_iTabsNum}

    CMDIChildWnd::OnMDIActivate: Function: $FUNCTION, {this} {bActivate} {pActivateWnd} {pActiveView}

    As you can see, first the already opened child frame is deactivated and the new one is activated, that seems ok.
    But then the old gets activated again and the new get's deactivated, why?
    SetActiveTab is called but why is it set back to 0 before setting to 1 (whitch is the already active one)?

    As you can see CMDIChildWnd::OnMDIActivate is called 3 times with 0 and 1, can you explain this?

    This sequence causes in my application and in the demo application flickering in the MDI Tab window, because the tab is switched 3 times from 0 to 1.
    Every tab switch causes a unnecessary redraw. This is in my application unwanted, because a lot of data may be shown that should not be redrawn.

    Thanks for the help,


    Andreas
    • Edited by cpp-hacker Wednesday, September 28, 2011 10:15 AM
    •  

All Replies

  • Sunday, November 06, 2011 1:03 AM
     
     

    I also have this problem.

  • Monday, January 09, 2012 9:41 AM
     
     

    Has anyone a solution or workaround for this?

    Thanks,


    Andreas
  • Monday, April 16, 2012 4:14 PM
     
     
    I have this problem as well and have lost a week to trying to figure it out so far.

    Rob Diaz: rob.diaz@msxgroup.com MSX Group: www.msxgroup.com MSX Group specializes in Forecaster, FRx and Management Reporter training, implementation and support.