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 » CustomizeStateLoad question Collapse All
Subject Author Date
tera tera May 8, 2009 - 10:19 PM

Hello.


Can I read only accelerator key information from Registry?

Should I use pRibbonBar->CustomizeStateLoad?

Technical Support May 11, 2009 - 11:38 AM

No, you should use the code similar to that present in the CExtCustomizeSite::CustomizeStateSerialize() method. The accelerator tables are stored in the CExtCustomizeSite::CCmdMenuInfo objects. Each CExtCustomizeSite::CCmdMenuInfo describes one menu tree linked to the document/view objects of MFC’s document/view architecture. Te accelerator table is linked to menu tree. The following code saves the menu info objects in the CExtCustomizeSite::CustomizeStateSerialize() method:

   // serialize menus
            DWORD dwMenuInfoCount = (DWORD)MenuInfoGetCount();
            ar << dwMenuInfoCount;
            for( DWORD i = 0; i < dwMenuInfoCount; i++ )
            {
                        CCmdMenuInfo * pCmdMenuInfo =
                                    MenuInfoGetAt( i );
                        ASSERT( pCmdMenuInfo != NULL );
                        CExtCustomizeCmdTreeNode * pMenuNode =
                                    pCmdMenuInfo->GetNode( false );
                        ASSERT_VALID( pMenuNode );
                        pMenuNode->Serialize( ar );
                        pCmdMenuInfo->AccelTableSerialize( ar );
            } // for( DWORD i = 0; i < dwMenuInfoCount; i++ )

The following code loads the menu info objects in the CExtCustomizeSite::CustomizeStateSerialize() method:
   // serialize menus
            DWORD dwMenuInfoCount = (DWORD)MenuInfoGetCount();
            DWORD dwMenuInfoCountA = 0;
            ar >> dwMenuInfoCountA;
            if( dwMenuInfoCountA != dwMenuInfoCount )
            {
                        ASSERT( FALSE );
#if _MFC_VER >= 0x0800
                        ::AfxThrowArchiveException( CArchiveException::genericException, NULL );
#else
                        ::AfxThrowArchiveException( CArchiveException::generic, NULL );
#endif
            }
            if( m_pWndMenuBar != NULL )
            {
                        ASSERT_VALID( m_pWndMenuBar );
                        m_pWndMenuBar->SetButtons();
            }
            DWORD i = 0;
            for( i = 0; i < dwMenuInfoCount; i++ )
            {
                        CCmdMenuInfo * pCmdMenuInfo =
                                    MenuInfoGetAt( i );
                        ASSERT( pCmdMenuInfo != NULL );
                        CExtCustomizeCmdTreeNode * pMenuNode =
                                    pCmdMenuInfo->GetNode( false );
                        ASSERT_VALID( pMenuNode );
                        pMenuNode->Serialize( ar );
                        pCmdMenuInfo->AccelTableSerialize( ar );
            } // for( i = 0; i < dwMenuInfoCount; i++ )
            if( m_pWndMenuBar != NULL )
            {
                        ASSERT_VALID( m_pWndMenuBar );
                        VERIFY( m_pWndMenuBar->UpdateMenuBar( FALSE ) );
            }
. . .
            if( (GetCustomizeFlags()&__ECSF_ACCELERATORS) != 0 )
                        OnUpdateAccelGlobalInfo( true );

Both code snippets have the following lines:
               pMenuNode->Serialize( ar );
                        pCmdMenuInfo->AccelTableSerialize( ar );

The first line invokes the CExtCustomizeCmdTreeNode::Serialize() method for serializing menu tree. The second line invokes the CExtCustomizeSite::CCmdMenuInfo::AccelTableSerialize() method for serializing accelerator table and that is what you need. You need to all the CExtCustomizeSite::CCmdMenuInfo objects using the CExtCustomizeSite::MenuInfo***() methods and invoke their CExtCustomizeSite::CCmdMenuInfo::AccelTableSerialize() method. This serialization is CArchive based. You can create CArchive object based on the CMemFile memory file and save it to the system registry or load it from there like demonstrated in the CExtCustomizeSite::CustomizeStateLoad() and CExtCustomizeSite::CustomizeStateSave() methods.