Professional UI Solutions
Site Map   /  Register


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 » changing text of command in a toolbar. Collapse All
Subject Author Date
armond glover Jun 1, 2009 - 8:45 PM


In our application, user has the capability to change the text and icon of any command on the toolbar. He can also drag commands to any toolbar, such that one command is present in more than one toolbar. I use the following code such that if he changes command text from "abc" to "abc1", it should be reflected to all instances of the button in various toolbars.

CExtCmdItem * pCmdItem = g_CmdManager->CmdGetPtr(strProfileName, nCmdID);

pCmdItem->m_sToolbarText = ptrCust->name;

This does not work. What should i do.



Technical Support Jun 2, 2009 - 12:55 PM

If you are using simple non-customizable toolbars, the CExtCmdItem::m_sToolbarText property is used as is and it defines text for toolbar buttons. If you changes it, you should recompute the layout of toolbar’s parent frame window.

If you are using customizable toolbars and menus, the CExtCmdItem::m_sToolbarText property is used for storing initial command’s text to be displayed in toolbar buttons. This initial text is used when user reset’s toolbar buttons via context menu in the customize mode. The customizable toolbar buttons are using text stored in the CExtCustomizeCmdTreeNode command tree node objects. The CExtCustomizeCmdTreeNode::GetTextInToolbar() and CExtCustomizeCmdTreeNode::SetTextInToolbar() methods are used for accessing and modifying the command’s text in toolbar. This text is initialized from the CExtCmdItem::m_sToolbarText property initially. Each cloned copy of the same command is able to keep and display different text because user can customize each toolbar button independently from each other. You should know that you can drag-n-drop customizable toolbar buttons and create copies of them. You also can create new toolbars. This means if you want to change text of some command in all its toolbar buttons, then you should analyze all the command trees of all the toolbars and all the menu objects too. The CExtCustomizeSite::CCmdMenuInfo menu information objects can be accessed using the CExtCustomizeSite::MenuInfo***() methods. The CExtCustomizeSite::CCmdMenuInfo::GetNode() can be used for accessing the active and initial command trees of the menu line. The CFrameWnd::m_listControlBars property contains all the control bars created inside the frame window. You should walk through all of them and review all the CExtToolControlBar objects but not the CExtMenuControlBar object. This is how you can enumerate all the toolbars. The CExtToolControlBar::GetCustomizeSite() method of each toolbar returns pointer to the customize site instance or NULL. This is how you can detect customizable toolbars. The CExtCustomizeSite::GetToolbarCmdNode() method returns pointer to the active or initial toolbar’s command tree node. Please note, the user defined toolbars created in the customize mode does not have initial command tree and does not support resetting in the customize mode. The CExtCustomizeSite::IsUserBarCommand() method can be used for checking whether toolbar is the user defined toolbar. This method should receive toolbar’s dialog control identifier in parameter. Now you can get root command tree nodes of each menu line and each toolbar. The next steps are: walk recursively through each command tree, detect commands to assign text in toolbar and/or to change other command properties by command identifier, change text in toolbar, etc. Finally you will need to redraw all the toolbars and, optionally, the menu bar for refreshing all the changed commands. The CExtCustomizeSite::RedrawCommandItems() does this work. It can refresh all the instances of the specified command in toolbars and menus.

In both cases (simple and customizable), if your code massively changes many toolbar commands, then you may have reason simply recompute layout of the main frame window and all the floating frame windows:

CMainFrame * pMainFrame = . . .
            CExtControlBar::stat_RedrawFloatingFrames( pMainFrame );
            CExtControlBar::stat_RecalcBarMetrics( pMainFrame );