【问题标题】:MFC ribbon interface gives assert failure when localizing appMFC 功能区界面在本地化应用程序时出现断言失败
【发布时间】:2012-10-17 10:15:19
【问题描述】:

我有一个基于 MFC 的应用程序,它使用 Office 2007 功能区界面。 MFC 是静态链接的。

我正在尝试添加日语本地化。我在单独的 DLL 中有本地化资源。我在InitInstance开头加载资源DLL:

VERIFY(hRes = LoadLibrary(_T("JapaneseLang.dll")));
if(hRes)
    AfxSetResourceHandle(hRes);

这会导致CMFCVisualManagerOffice2007::OnUpdateSystemColors 的断言失败

#if !defined _AFXDLL
        TRACE(_T("\r\nImportant: to enable the Office 2007 look in static link,\r\n"));
        TRACE(_T("include afxribbon.rc from the RC file in your project.\r\n\r\n"));
        ASSERT(FALSE);
#endif

但我确实在 DLL 和 EXE 的 rc 文件中包含了afxribbon.rc


我还发现了一个similar question asked at tech-archive.net 和一个possible solution 在那里概述

现在我找到了错误位置。这应该是新 mfc 的错误 版本。

在CMFCVisualManagerOffice2007中,当样式发生变化时, CMFCVisualManagerOffice2007自动调用FreeLibrary的SetStyle函数 释放dll,所以错误发生了。

现在我从 CMFCVisualManagerOffice2007 派生了一个类并添加了一个 通过执行设置成员变量 m_bAutoFreeRes 的静态函数 这个应用程序可以正常运行;见下文。

类 CMFCVisualExtManagerOffice2007:公共 CMFCVisualManagerOffice2007 { DECLARE_DYNCREATE(CMFCVisualExtManagerOffice2007) 公共: CMFCVisualExtManagerOffice2007();虚拟的 ~CMFCVisualExtManagerOffice2007();

静态无效 SetAutoFreeRes(BOOL bAutoFree = FALSE) { m_bAutoFreeRes = b自动释放; } };


但我无法理解究竟是什么导致了这个问题,以及这个解决方案是如何工作的。另外我不确定这是否是正确的解决方案。有谁知道究竟是什么导致了这个问题,以及解决方案是如何工作的?

【问题讨论】:

    标签: c++ localization mfc ribbon assert


    【解决方案1】:

    我弄清楚了解决方案的工作原理。每次调用CMFCVisualManagerOffice2007::SetStyle 后,我需要将m_bAutoFreeRes 设置为false。

    class CMFCVisualExtManagerOffice2007 : public CMFCVisualManagerOffice2007
    {
        DECLARE_DYNCREATE(CMFCVisualExtManagerOffice2007)
    public:
        CMFCVisualExtManagerOffice2007();
        virtual ~CMFCVisualExtManagerOffice2007();
    
        static void SetAutoFreeRes(BOOL bAutoFree = FALSE)
        {
            m_bAutoFreeRes = bAutoFree;
        }
    };
    

    然后在主题之间切换时

        switch (m_nAppLook)
        {
        case ID_VIEW_APPLOOK_OFF_2007_BLUE:
            CMFCVisualManagerOffice2007::SetStyle (CMFCVisualManagerOffice2007::Office2007_LunaBlue);
            CMFCVisualExtManagerOffice2007::SetAutoFreeRes(FALSE);
            break;
    
        case ID_VIEW_APPLOOK_OFF_2007_BLACK:
            CMFCVisualManagerOffice2007::SetStyle (CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
            CMFCVisualExtManagerOffice2007::SetAutoFreeRes(FALSE);
            break;
    
        case ID_VIEW_APPLOOK_OFF_2007_SILVER:
            CMFCVisualManagerOffice2007::SetStyle (CMFCVisualManagerOffice2007::Office2007_Silver);
            CMFCVisualExtManagerOffice2007::SetAutoFreeRes(FALSE);
            break;
    
        case ID_VIEW_APPLOOK_OFF_2007_AQUA:
            CMFCVisualManagerOffice2007::SetStyle (CMFCVisualManagerOffice2007::Office2007_Aqua);
            CMFCVisualExtManagerOffice2007::SetAutoFreeRes(FALSE);
            break;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      相关资源
      最近更新 更多