MFC MDI 从属性对话框动态更改选项卡样式

发布于 2025-01-15 23:44:57 字数 3828 浏览 3 评论 0原文

由于家人去世,我开发应用程序已经过去 10 个月了,我刚刚开始再次查看它,但仍然不确定如何解决问题。

项目查询/帮助从这里开始:

MFC MDI 收集控件“应用”按钮例程的状态

由于这是一个特定的重点问题,我不想搞乱我的其他线程,所以我想做的是在视图之后更改文档选项卡样式已加载。我知道这是可以完成的,因为 Microsoft 的主存储库包含所有代码示例,有一个名为 VCSamples-master\VCSamples-master\VC2010Samples\MFC\Visual C++ 2008 Feature Pack\TabControl 的项目,我将其看过。我突然意识到,即使我可以遵循它的代码,调用也是来自 MDI 窗口本身,我的问题是我试图通过使用 OnApply 的属性页对话框来完成此操作,这会改变一些事情。

在上面的 OutputPane 线程的帮助下,我能够成功地完成其中的一部分,因为我能够获取窗格句柄并执行。有人告诉我,对于创建后的 MDI 选项卡,我需要解析选项卡、对它们进行计数,然后执行。所以我的问题是在捕获选项卡后……如何更改它们的样式。

这是代码:

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;
}

如果我能弄清楚最后一部分,我基本上就完成了,我只是似乎无法找到如何通过 OnApply

我可以看到任何建议或实际代码示例来解决我的问题吗?

仅供参考:不,我没有时间采取额外的 OOP 来解决这个问题。我希望有人可以提供一些指导,以便我在解决此问题后可以继续前进。

谢谢, Chris

编辑 1:

所以我仔细研究了 Constantine 的建议,这就是我的想法:

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;
}

当我选择单选按钮时,m_styles_tabs 的索引值是 0-8。代码编译并运行,当我中断它时,我看到索引值发生变化,但 MDI 的选项卡仍然没有更新。根据此处显示的成员,编辑的代码是否有意义:

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

我认为这是正确的方向,我错过了什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文