My application is written with the MFC Feature Pack (VS2012). It can switch UI localization by loading data from a resource dll. But the CMFCMenuBar
menu restores the original text of menu items when the application is reloaded.
If I use 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. 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. 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.
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;
}
}
P.S.: For better result you should add such serialization code to all your toolbar and dockable bar classes.