1 year ago

#313745

test-img

Kittmaster

MFC MDI dynamically changing tab style from a property dialog

It has been 10 months since I worked on my app due to a death in the family, just started looking at it again and still not sure how to solve the problem.

The project inquires/help started here:

MFC MDI Collecting control states for the "apply" button routine

Since this is a specific focused question, I didn't want to muck up my other thread, so what I'd like to do is change the documents tab styles after the view is loaded. I know that this can be done because the master repository from Microsoft with all the code examples has a project called VCSamples-master\VCSamples-master\VC2010Samples\MFC\Visual C++ 2008 Feature Pack\TabControl which I have looked at. It dawns on me that even though I can follow its code, the calls are from within the MDI window itself where my issue is I'm trying to do this via a property page dialog using OnApply which changes things.

I was able to do part of this properly with the help of the thread above to the OutputPane successfully because I was able to get the Pane handle and execute. I was told that for the MDI tabs after creation that I need to parse the tabs, count them, and then execute. So my issue here is after I capture the tabs......how to change their styles.

Here is the code as it stands:

BOOL CSettingsUserTabs::OnApply()
{
    BOOL bResult = CMFCPropertyPage::OnApply();
    if (bResult)
    {
        // Update Output Pane Tab Styles (Works 100%)
        AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs); // Save value to registry
        ((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);     
        ((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();

        //Get the open file tabs in the MDI
        for (POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); pos != NULL; )
        {
            CDocTemplate* pTempl = AfxGetApp()->GetNextDocTemplate(pos);

            for (POSITION pos1 = pTempl->GetFirstDocPosition(); pos1 != NULL; )
            {
                CDocument* pDoc = pTempl->GetNextDoc(pos1);

                for (POSITION pos2 = pDoc->GetFirstViewPosition(); pos2 != NULL; )
                {
                    CView* pView = pDoc->GetNextView(pos2);
                    if (pView->IsKindOf(RUNTIME_CLASS(CTrainView)))
                    {

                        
                    // THIS IS WHERE MY ISSUE IS, NOW THAT ALL THE TABS ARE
                    // CAPTURED, HOW DO I ADDRESS THEM LIKE WHAT IS SHOWN
                    // ABOVE:
                    
                    //((CMainFrame*)AfxGetMainWnd())->xxxxxx.yyyyyy.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);   

                        
                    
                    }
                }
            }
        }
    }
    return bResult;
}

If I can figure this last piece out, I'll be basically finished, I just can't seem to find a solution on how to do this via property sheet via OnApply.

Any suggestions or actual code examples I can see to solve my problem?

FYI: No, I haven't had any time to take additional OOP to solve this. I'm hoping someone can provide some guidance so I can move on after getting this sorted.

Thanks, Chris

EDIT 1:

So I took a closer look at Constantine's suggestion and here is what I came up with:

BOOL CSettingsUserTabs::OnApply()
{
    BOOL bResult = CMFCPropertyPage::OnApply();
    if (bResult)
    {
        // Update Output Pane Tab Styles
        AfxGetApp()->WriteProfileInt(_T("Settings"), _T("UserTabStyle"), m_style_tabs); // Save value to registry
        ((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);     
        ((CMainFrame*)AfxGetMainWnd())->m_wndOutput.m_wndTabs.RecalcLayout();


    CMFCTabCtrl& MDI_STYLES = ((CMainFrame*)AfxGetMainWnd())->GetMDITabs();
    MDI_STYLES.ModifyTabStyle((CMFCTabCtrl::Style)m_style_tabs);
    MDI_STYLES.RecalcLayout();
    CMDIFrameWndEx* pMainFrame = DYNAMIC_DOWNCAST(CMDIFrameWndEx, GetTopLevelFrame());
        pMainFrame->SetFocus();
        pMainFrame->RecalcLayout();
    }
    return bResult;
}

The m_styles_tabs is getting the index value of 0-8 when I select the radio button. The code compiles and runs and I see the index value change when I break on it, but the tabs for the MDI are still not updating. Does the edited code make sense based on the members shown here:

https://learn.microsoft.com/en-us/cpp/mfc/reference/cmfctabctrl-class?view=msvc-170#modifytabstyle

I think this the right direction, am I missing something?

visual-c++

mfc

visual-studio-2017

apply

mdi

0 Answers

Your Answer

Accepted video resources