简体   繁体   English

如何禁用MFC Feature Pack应用程序中的MenuBar项目中的文本恢复?

[英]How to disable the restoration of text in MenuBar items in an MFC Feature Pack application?

My application is written with the MFC Feature Pack (VS2012). 我的应用程序是使用MFC Feature Pack(VS2012)编写的。 It can switch UI localization by loading data from a resource dll. 它可以通过从资源dll加载数据来切换UI本地化。 But the CMFCMenuBar menu restores the original text of menu items when the application is reloaded. 但是,当重新加载应用程序时, CMFCMenuBar菜单将还原菜单项的原始文本。

If I use GetDockingManager()->DisableRestoreDockState(TRUE); 如果我使用GetDockingManager()->DisableRestoreDockState(TRUE); , it blocks all layout data from being restored rather than only text data. ,它阻止所有布局数据被还原,而不仅仅是文本数据。

I know that the MFC Feature Pack serializes many of the UI elements. 我知道MFC功能包序列化了许多UI元素。 If possible, how can I disable text data serialization to achieve this? 如果可能,如何禁用文本数据序列化以实现此目的?

I found good solution. 我找到了很好的解决方案。 Main idea is to store LANGID with menu buttons data also. 主要思想是还将LANGID与菜单按钮数据一起存储。 When menu bar performs load process we need to check stored LANGID and current process LANGID and to reset bar if they are not equivalent. 当菜单栏执行加载过程时,我们需要检查存储的LANGID和当前进程的LANGID,并在它们不相等时重置栏。

Code: 码:

class CLocalyMenuBar
    : public CMFCMenuBar
{
    DECLARE_SERIAL(CLocalyMenuBar)

public:
    typedef CMFCMenuBar TBase;

public:
    CLocalyMenuBar();
    virtual ~CLocalyMenuBar();

    virtual void        Serialize(CArchive& ar);
};



IMPLEMENT_SERIAL(CLocalyMenuBar, CLocalyMenuBar::TBase, VERSIONABLE_SCHEMA | 1)

CLocalyMenuBar::CLocalyMenuBar()
{}

CLocalyMenuBar::~CLocalyMenuBar()
{}

void CLocalyMenuBar::Serialize(CArchive& ar)
{
    TBase::Serialize(ar);

    if (ar.IsLoading()) {

        LANGID nID = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
        ar >> nID;

        if ((nID != Locality::GetCurResourceLANGID()) && CanBeRestored()) {
            RestoreOriginalState();
        }
    }
    else {
        ar << Locality::GetCurResourceLANGID();
    }
}


namespace Locality {

    LANGID GetCurResourceLANGID()
    {
        // You should return current resource LANGID for your app process!
        return MY_PROCESS_CURRENT_LANGID;
    }
}

PS: For better result you should add such serialization code to all your toolbar and dockable bar classes. PS:为了获得更好的结果,您应该将这样的序列化代码添加到所有工具栏和可停靠的酒吧类中。

As all with serializing code, one object serializes other. 正如所有带有序列化代码的对象一样,一个对象可以序列化其他对象。

CMFCMenuBar finally serializes the items with CBCGPToolbarButton::Serialize. 最后,CMFCMenuBar使用CBCGPToolbarButton :: Serialize对项目进行序列化。 And if you look inside this code you find that the text is stored and reloaded there... 如果您查看这段代码,就会发现该文本已存储并重新加载在那里。

So the only chance you have is to change all controls in the toolbar to be of your class. 因此,您唯一的机会就是将工具栏中的所有控件都更改为您的班级。 And this is nearly impossible. 这几乎是不可能的。 Changing the behavior in the serialization isn't a possible way. 在序列化中更改行为是不可能的。

So from my point of view, there is no good answer to your question, except choosing a different approach. 因此,从我的角度来看,除了选择其他方法之外,对您的问题没有很好的答案。

to get ONLY the text removed and still save positions/customization of the menu... 仅删除文本并仍然保存菜单的位置/自定义...

you would have to over ride the CMFCToolbarButton class and use that button in the places you don't want saved. 您将不得不改用CMFCToolbarButton类,并在您不想保存的位置使用该按钮。 In CMFCMenuBar there might be a way to pass down the class type used for buttons. 在CMFCMenuBar中,可能有一种方法可以传递用于按钮的类类型。 then your button class could have a BOOL that toggles save text on or off. 那么您的按钮类可能会有一个BOOL,可以切换打开或关闭保存文本。

If there is not a way to pass down button class type in the menu, then you would have to override the guy creating those buttons. 如果没有办法在菜单中传递按钮类的类型,那么您将不得不覆盖创建这些按钮的家伙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM