theEagles

I am sailing, to be with you, to be free.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MFC MDI disable tab's Close button

Posted on 2012-08-28 11:32  theEagles  阅读(721)  评论(0)    收藏  举报
Disable Close button
void CChildFrame::OnSetFocus(CWnd* pOldWnd)
{

    CMainFrame* pFrame= (CMainFrame*) AfxGetMainWnd(); //Get Handle to MainFrame
    CMDIChildWnd* pActiveChild = pFrame->MDIGetActive();
    CView* pActivateView = pActiveChild->GetActiveView();

    if ( pActiveChild != NULL ){
        CDocument* pDoc = (CPeterRobertsConsultingDoc*)pActiveChild->GetActiveDocument();
    

        if(((NULL != pDoc) && pActivateView->IsKindOf(RUNTIME_CLASS(cMainView))))
        {
            //View IS cMainView and should not be closed            

            CMDITabInfo mdiTabParams;
            mdiTabParams.m_style = CMFCTabCtrl::STYLE_3D_ONENOTE; // other styles available...
            mdiTabParams.m_bActiveTabCloseButton = false;      // set to FALSE to place close button at right of tab area
            mdiTabParams.m_bTabIcons = FALSE;    // set to TRUE to enable document icons on MDI taba
            mdiTabParams.m_bAutoColor = TRUE;    // set to FALSE to disable auto-coloring of MDI tabs
            mdiTabParams.m_bDocumentMenu = TRUE; // enable the document menu at the right edge of the tab area
            mdiTabParams.m_bTabCloseButton = false;
            pFrame->EnableMDITabbedGroups(TRUE, mdiTabParams);
                
        }else{

            CMDITabInfo mdiTabParams;
            mdiTabParams.m_style = CMFCTabCtrl::STYLE_3D_ONENOTE; // other styles available...
            mdiTabParams.m_bActiveTabCloseButton = true;      // set to FALSE to place close button at right of tab area
            mdiTabParams.m_bTabIcons = FALSE;    // set to TRUE to enable document icons on MDI taba
            mdiTabParams.m_bAutoColor = TRUE;    // set to FALSE to disable auto-coloring of MDI tabs
            mdiTabParams.m_bDocumentMenu = TRUE; // enable the document menu at the right edge of the tab area
            mdiTabParams.m_bTabCloseButton = true;
            pFrame->EnableMDITabbedGroups(TRUE, mdiTabParams);
        }
    }


CMDIChildWndEx::OnSetFocus(pOldWnd);
}

 

参考资料:http://www.3dbuzz.com/vbforum/showthread.php?185778-MFC-MDI-TabbedView-Disabling-Close