Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2008
    Posts
    397

    MFC-MDI-TabbedView-Disabling Close

    I Have a tabbed view MDI app, which some of you may know.

    I am trying to Disable the Close button on the First Tab (I have Multiple Type Views all are formviews) So I have put it in my cMainView as that is the one that loads first as it wont affect the other types

    Now the statement below works when I pass in the Parent
    Code:
    BOOL cMainView::EnableCloseButton(const CWnd *wnd, const BOOL bState)
    {
    	CMenu *menu;
    
    	if (wnd == NULL) return FALSE;
    	if ((menu = wnd->GetSystemMenu(FALSE)) == NULL) return FALSE;
    	return menu->EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | bState ? MF_ENABLED : MF_GRAYED) != -1;
    }
    but when I try and pass in the Active window below it does nothing


    Code:
    		CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
    		
                    //CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->MDIGetActive()->GetActiveView();
    		
                    CMDIChildWnd *pChild = pFrame->MDIGetActive();
    
    		EnableCloseButton(pChild, FALSE);

  2. #2
    Join Date
    Nov 2008
    Posts
    397
    Got it OMG, took ages and is surprisingly simple, in cMainFrame in the Create function it showed these

    Code:
    	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);
    where the Line " mdiTabParams.m_bActiveTabCloseButton = false; " Shows The close button on the tab, disabled it shows it in the far right corner

    and the "mdiTabParams.m_bTabCloseButton = false;" disables the close in the far right corner

    so I used that in CChildFrame on Set Focus to have

    Code:
    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);
    }

    using this it allows the first document to have no close (you could also write your own close function with this statement)
    and allows me to close all others that don't have the Viewtype set to cMainView

    hope this helps people who have been looking for anything similar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •