0
votes

I have an MDI MFC FEATURE PACK app in vs2008.

I do need to determine what child window(s) are visible , even if multiple tab groups are created by the user, and also what is the last activated MDI child. I have found that in my mainframe CMDIFrameWndEx class, the methods

m_wndClientArea.FindActiveTabWnd ();
m_wndClientArea.GetFirstTabWnd ();
m_wndClientArea.GetNextTabWnd (); 

that could potentially let me navigate through all tab grops. Trouble is that these methods return an CMFCTabControl that does not offer any method/member to obtain an pointer to the MDI child windows in the tab. It only gives the index of the active tab. So how do I get the CMDIChildWndEx* pointer of the "in front" window of the given tabgroup?

2

2 Answers

1
votes

Because your CMDIChildWndEx instances are wrapped in a tab control wrapper you can get the active tab and then the wnd from that, e.g.

int nActive = pTabCtrl->GetActiveTab();
CWnd * pWnd = pTabCtrl->GetTabWndNoWrapper( nActive );

CMDIChildWndEx * pChild = dynamic_cast<CMDIChildWndEx*>(pWnd);
1
votes

It was wonderful to find this code - exactly what I needed to redraw my active tab windows in each tab group since with multiple (split) tab groups, they were not being redrawn correctly. However, to make the loop work I had to do the following (CChildFrame is my derived frame type):

m_arrpActiveChilds.RemoveAll (); 
const CObList& TabGroups =m_wndClientArea.GetMDITabGroups(); 
if (TabGroups.GetCount ()>0) { 
    POSITION crtPos = TabGroups.GetHeadPosition (); 
    CMFCTabCtrl* pCrtTabCtrl;

    do { 
        pCrtTabCtrl=DYNAMIC_DOWNCAST(CMFCTabCtrl, TabGroups.GetNext(crtPos)); 
        int nActive = pCrtTabCtrl->GetActiveTab(); 
        CWnd * pWnd = pCrtTabCtrl->GetTabWndNoWrapper( nActive ); 
        CChildFrame * pChild = dynamic_cast<CChildFrame*>(pWnd); 
        m_arrpActiveChilds.Add (pChild);
    } while(crtPos != NULL);