Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Change language in Menu, toolbar. category in Customize Mode Collapse All
Subject Author Date
Stephan Finkler Jan 12, 2005 - 3:03 AM

My way to change the language is loading a string from a language dependent text file.
If I change the language I load the string with the same id from another file.
Theres is only one resource for the menu and toolbar in all languages.
(Problem with SetLangIdDesired() )

How can I implement this in an easy way?

My idea is:
- Get all the registered cmds
- set the new text for each cmd
- update menu, toolbars and categorys

something like
//////////////////////////////////////
g_ResourceManager->SetLangIdDesired(__EXT_MFC_LANG_ID_GERMAN);

if (!CExtCustomizeSite::EnableCustomization(this)) {
ASSERT(FALSE);
return -1;
}
CExtCustomizeSite::CategoryUpdate( IDR_GVIEWSTYLE );
CExtCustomizeSite::CategoryUpdate( IDR_MAINFRAME );
    CExtCustomizeSite::CategoryMakeAllCmdsUnique();
    CExtCustomizeSite::CategoryAppendAllCommands();
CExtCustomizeSite::CategoryAppendNewMenu();

...

Node = GetRootNodeOfAllRegisteredMenus();
while (Node) {

CExtCmdManager::cmd_t * p_cmd;
pCmd = g_CmdManager->CmdGetPtr( theApp.m_pszProfileName, pNode->GetCmdID() );

ASSERT( p_cmd != NULL );
p_cmd->m_sMenuText = LoadStringFromFile(MyID);
p_cmd->m_sToolbarText = LoadStringFromFile(MyID);

Node = GetNextNode();
}

....

MenuUpdate();
ToolbarUpdate();
CategoryUpdate();

//////////////////////////////////////

Technical Support Jan 13, 2005 - 6:42 AM

Dear Stephan,


We guess the beginning of your CMainFrame::OnCreate() method contains the command profile initialization code with resource updating from all the menus and toolbars. Immediately after this point you may insert the following code which will walk through all the command items and may load their strings:

CExtCmdProfile * pProfile =
            g_CmdManager->ProfileGetPtr(
                        _T("profile name")
                        );
POSITION pos = pProfile->m_cmds.GetStartPosition();
            for( ; pos != NULL; )
            {
                        UINT nCmdID;
                        CExtCmdItem * pCmdItem = NULL;
                        pProfile->m_cmds.
                                    GetNextAssoc(
                                                pos,
                                                nCmdID,
                                                pCmdItem
                                                );
                        ASSERT( pCmdItem != NULL );
                        pCmdItem->m_sMenuText = . . .
                        pCmdItem->m_sToolbarText = . . .
                        pCmdItem->m_sTipTool = . . .
                        pCmdItem->m_sTipStatus = . . .
                        pCmdItem->m_sAccelText = . . .
            }

This method is enough simple but it can be applied only if you need to load localized resources only at the application startup. If you need to load them on-the-fly, then you will to walk through all the command trees stored in the CExtCustomizeSite. Please let us know whether you interested in the last task.

Stephan Finkler Jan 13, 2005 - 11:50 AM

I would like to change the language on-the-fly.

Also I have serialization. So I have to change the language after I load it from an archive.

By the way, how can I update the categories when I have changed the menu text ?

Technical Support Jan 14, 2005 - 5:42 AM

The LanguageSwitcher sample application performs just what you need but it loads strings and bitmaps from resources. You should learn how it works before porting this feature into your application. This sample uses several helper methods in the CMainFrame class to perform unified UI initialization during startup or on-the-fly language switching. You should port these methods into your application. The CMainFrame::_UpdateCommandManager method initializes the Command Manager. You need to load your strings from a text file and put them into the Command Manager here. The CMainFrame::_SetStatusBarIndicators method initializes the status bar. The CMainFrame::_ConfigureCustomizeSite, CMainFrame::_ReloadNodeFromCommandManager and CMainFrame::_ResetAllCommandTrees methods are responsible for initializing all command trees in the Customize Site that corresponds to your frame window. These methods will reinitialize all command categories, toolbars and menus. You should use them "as is".