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 » Adding / removing menu resources Collapse All
Subject Author Date
Kishore Gagrani Dec 9, 2003 - 6:51 AM

I have an application that has customization enabled, and I was wondering how changes to my menus get propagated to the users of my app. I have a 1.0 version of my app that has customization, and in my 1.1 version I want change my menu resources (add some for a new feature, and remove some for a feature that changed). When I run the app, my newly added menu items don’t appear, which I assume is being caused by the customization feature reading in the old menu from the registry. I also get a bunch of asserts when I run in debug mode because the commands being read from the registry no longer exist in the app for the removed menu items. Is there any way I can get around these issues when I ship my new version, apart from clearing the user’s registry entries? Some Visual Studio plug-ins seem to clear the registry and I despise having to recreate all my menus and toolbars again.

Technical Support Dec 11, 2003 - 2:09 AM

Dear Kishore,

The Prof-UIS customization subsystem stores two versions of the menu trees: initial and current (or customized). It is the customized version that is loaded from the registry every time. The menu bar always display the customized version of the menu trees. To reset the menu bar, you need to use the initial version. So, when your new version 1.1 loads its initial menu tree, you should copy it to the current (customized) version of the menu or, in other words, you should reset the menu bar.

First, please get both command trees:

	CExtCustomizeSite::CCmdMenuInfo * pMenuInfo =
		CExtCustomizeSite::MenuInfoGetByName(
			_T("Default") // menu name
			);
	CExtCustomizeCmdTreeNode * pNodeInitial =
		pMenuInfo-> GetNode( true );
	CExtCustomizeCmdTreeNode * pNodeCustomized =
		pMenuInfo-> GetNode( false );


Then, reset the current menu tree:
	 (*pNodeCustomized) = (*pNodeInitial);

Kishore Gagrani Dec 15, 2003 - 7:51 AM

Thanks for the response. Where exactly am I supposed to put this code? When I put this code in (see below), I get asserts during ProfileBarStateLoad(). If I put the code after the state loading, I still get an assert when trying to show my main window.

I tried to do the following (during CMainFrame::OnCreate()):

   VERIFY(g_CmdManager->ProfileSetup( AfxGetApp()->m_pszProfileName, GetSafeHwnd()));
   VERIFY( g_CmdManager->UpdateFromMenu( AfxGetApp()->m_pszProfileName, IDR_MAINFRAME ));
   VERIFY( g_CmdManager->UpdateFromMenu( AfxGetApp()->m_pszProfileName, IDR_PROJECT ));
   VERIFY( g_CmdManager->UpdateFromToolBar( AfxGetApp()->m_pszProfileName, IDR_FILETOOLBAR ));
   VERIFY( g_CmdManager->UpdateFromToolBar( AfxGetApp()->m_pszProfileName, IDR_VIEWTOOLBAR ));
   VERIFY( g_CmdManager->UpdateFromToolBar( AfxGetApp()->m_pszProfileName, IDR_TOOLSTOOLBAR ));
   VERIFY( g_CmdManager->UpdateFromToolBar( AfxGetApp()->m_pszProfileName, IDR_HELPTOOLBAR ));

   VERIFY( CreateMenuBar());
   EnableDocking( CBRS_ALIGN_ANY );
   VERIFY( CreateFileToolBar());
   VERIFY( CreateViewToolBar());
   VERIFY( CreateToolsToolBar());
   VERIFY( CreateHelpToolBar());
   VERIFY( CreateStatusBar());
   VERIFY(CExtControlBar::FrameInjectAutoHideAreas( this ));

#if (!defined __EXT_MFC_NO_CUSTOMIZE)
   VERIFY( CExtCustomizeSite::MenuInfoAdd( this,
                                           _T("Default"),
                                           IDR_MAINFRAME,
                                           true,
                                           false,
                                           RUNTIME_CLASS( CMainFrame )));
   VERIFY( CExtCustomizeSite::MenuInfoAdd( this,
                                           _T("Project"),
                                           IDR_PROJECT,
                                           false,
                                           false,
                                           RUNTIME_CLASS( CProjectFrame ),
                                           RUNTIME_CLASS( CProjectView ),
                                           RUNTIME_CLASS( CProjectDoc )));

   VERIFY( CExtCustomizeSite::MenuInfoLoadAccelTable( _T("Default"), IDR_MAINFRAME ));
   VERIFY( CExtCustomizeSite::MenuInfoLoadAccelTable( _T("Project"), IDR_PROJECT ));

   DWORD dwCustomizeOptions = __ECSF_BARS | __ECSF_COMMANDS | __ECSF_USER_BARS | __ECSF_PARMS;
   VERIFY( CExtCustomizeSite::EnableCustomization( this, dwCustomizeOptions) );
   CExtCustomizeSite::CategoryUpdate( IDR_MAINFRAME );
   CExtCustomizeSite::CategoryUpdate( IDR_PROJECT );
   CExtCustomizeSite::CategoryMakeAllCmdsUnique();
   CExtCustomizeSite::CategoryAppendAllCommands();
   CExtCustomizeSite::CategoryAppendNewMenu();
   CExtCustomizeSite::CustomizeStateLoad( AfxGetApp()->m_pszRegistryKey,
                                          AfxGetApp()->m_pszProfileName,
                                          AfxGetApp()->m_pszProfileName );
   if (bResetMenus)
   {
      CExtCustomizeSite::CCmdMenuInfo *pMenuInfo =
               CExtCustomizeSite::MenuInfoGetByName( _T("Default" ) );// menu name
      CExtCustomizeCmdTreeNode *pNodeInitial;
      CExtCustomizeCmdTreeNode *pNodeCustomized;

      pNodeInitial = pMenuInfo->GetNode( true );
      pNodeCustomized = pMenuInfo->GetNode( false );
      (*pNodeCustomized) = (*pNodeInitial);


      //reset Project menu
      pMenuInfo = CExtCustomizeSite::MenuInfoGetByName( _T("Project" ) );// menu name

      pNodeInitial = pMenuInfo->GetNode( true );
      pNodeCustomized = pMenuInfo->GetNode( false );
      (*pNodeCustomized) = (*pNodeInitial);
   }
#endif // (!defined __EXT_MFC_NO_CUSTOMIZE)

   if ( !CExtControlBar::ProfileBarStateLoad( this,
                                              AfxGetApp()->m_pszRegistryKey,
                                              AfxGetApp()->m_pszProfileName,
                                              AfxGetApp()->m_pszProfileName,
                                              &m_dataFrameWP ))
   {
      ResetWorkspace();
   }

   VERIFY( g_CmdManager->SerializeState( AfxGetApp()->m_pszProfileName,
                                         AfxGetApp()->m_pszRegistryKey,
                                         AfxGetApp()->m_pszProfileName,
                                         FALSE ));

Technical Support Dec 18, 2003 - 7:13 AM

Dear Kishore,


Your source code looks OK. We need additional information (i.e. the file name and line number) on the assertion with loading the bar state.