Summary: Demonstrates how to display a toolbar in a toolbar collection, or workspace, file.
The following source code example demonstrates how to display a toolbar in a toolbar collection, or workspace, file. This example assumes that there is a toolbar collection file (*.tb) with the same file name as the plug-in, and that the toolbar collection is stored in the same folder as the plug-in.
BOOL LoadAndShowPlugInToolbar() { // Get reference to our plug-in object CTestPlugIn& plugin = GetTestPlugIn(); // Get the full path to plug-in file ON_wString file_name; plugin.GetPlugInFileName( file_name ); // Build the toolbar collection file name wchar_t drive[_MAX_DRIVE]; wchar_t dir[_MAX_DIR]; wchar_t fname[_MAX_FNAME]; _wsplitpath( file_name, drive, dir, fname, 0 ); ON_wString collection_name; collection_name.Format( L"%s%s%s.tb", drive, dir, fname ); BOOL rc = FALSE; // Get reference to Rhino's toolbar manager CRhinoAppUiToolBarManager& tm = RhinoApp().RhinoUiToolBarManager(); // Load the toolbar collection, if necessary. if( tm.ReadFile(collection_name, true, true, true) ) { // Get the toolbar collection const CRhinoUiToolBarCollection* col = tm.Collection( tm.CollectionIndex(collection_name, false) ); if( col ) { // Find the "Default" toolbar const CRhinoUiToolBar* tb = col->ToolBar( col->FindToolBar(L"Default") ); if( tb && tm.ShowToolBar(tb, true, false) ) // Load it rc = TRUE; } } return rc; }
BOOL ShowPlugInToolbar() { // Get reference to our plug-in object CTestPlugIn& plugin = GetTestPlugIn(); // Get the full path to plug-in file ON_wString file_name; plugin.GetPlugInFileName( file_name ); // Build the toolbar collection file name wchar_t drive[_MAX_DRIVE]; wchar_t dir[_MAX_DIR]; wchar_t fname[_MAX_FNAME]; _wsplitpath( file_name, drive, dir, fname, 0 ); ON_wString collection_name; collection_name.Format( L"%s%s%s.tb", drive, dir, fname ); // Get reference to Rhino's toolbar manager CRhinoToolBarManager& tm = ToolBarManager(); // See if the toolbar collection is already open int collection_index = tm.CollectionIndex( collection_name, FALSE ); if( collection_index < 0 ) { // Open the toolbar collection collection_index = tm.OpenCollection( collection_name ); if( collection_index >= 0 ) { // Help Rhino figure out where all toolbars are supposed // to be positioned AFX_MANAGE_STATE( ::RhinoApp().RhinoModuleState() ); ((CFrameWnd*)AfxGetMainWnd())->RecalcLayout(); } } BOOL rc = FALSE; if( collection_index < 0 ) return rc; // See if our toolbar is available int toolbar_index = tm.ToolBarIndex( collection_index, L"Default" ); if( toolbar_index >= 0 ) { // If the toolbar is not visible, display it if( !tm.IsToolBarVisisble(collection_index, toolbar_index) ) rc = tm.ShowToolBar( collection_index, toolbar_index, TRUE ); else rc = TRUE; } return rc; }