Professional User Interface Suite, Copyright FOSS Software Inc. Help Published with Permission.

Below are typical steps the developer should follow when creating an application featuring Prof-UIS customization.

The initialization of the frame is performed in the OnCreate() method of the main frame window:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1;
. . .

In case of the SDI application, the view is created.

The profile of the command manager is set up and the commands are registered in it:

CWinApp * pApp = ::AfxGetApp();
ASSERT( pApp != NULL );
ASSERT( pApp->m_pszRegistryKey != NULL );
ASSERT( pApp->m_pszRegistryKey[0] != _T('\0') );
ASSERT( pApp->m_pszProfileName != NULL );
ASSERT( pApp->m_pszProfileName[0] != _T('\0') );
ASSERT( pApp->m_pszProfileName != NULL );
VERIFY( g_CmdManager->ProfileSetup(pApp->m_pszProfileName, GetSafeHwnd() )
&& g_CmdManager->UpdateFromMenu( pApp->m_pszProfileName, IDR_MAINFRAME )
&& g_CmdManager->UpdateFromMenu( pApp->m_pszProfileName, IDR_any_other_menu_resource)
&& g_CmdManager->UpdateFromToolBar( pApp->m_pszProfileName, ID_any_toolbar_resource )
);

All control bars are created, frame windows and docking bars are set up, and command usage statistics is loaded:

m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBarStandard.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBarUiLook.EnableDocking(CBRS_ALIGN_ANY);
if( !CExtControlBar::FrameEnableDocking(this) )
{
ASSERT( FALSE );
return -1;
}
VERIFY(
g_CmdManager->SetBasicCommands(pApp->m_pszProfileName,
g_statBasicCommands)
);
g_CmdManager->SerializeState(
pApp->m_pszProfileName,
pApp->m_pszRegistryKey,
pApp->m_pszProfileName,
false
);

The default menu in case of the MDI application or only one menu in case of the SDI application is registered:

VERIFY(CExtCustomizeSite::MenuInfoAdd(this, _T("Default"),IDR_MAINFRAME,true));
VERIFY(CExtCustomizeSite::MenuInfoLoadAccelTable(_T("Default"),IDR_MAINFRAME));

All documents of the MDI application are registered:

VERIFY(CExtCustomizeSite::MenuInfoAdd(this, _T("Document"),IDR_DOC_TYPE, true));
VERIFY(CExtCustomizeSite::MenuInfoLoadAccelTable(_T("Document"),IDR_MAINFRAME or IDR_DOC_TYPE_ACCEL_TABLE));

The necessary settings can be made for command trees and menus. At this step, the developer can change the structure of any tree, register some text/combobox fields or color commands, modify keyboard accelerator tables, and etc. For example, to reinitialize a registered menu and set its initial state, you should do the following:

CExtCustomizeCmdTreeNode * pMenuNodeInitial =
CExtCustomizeSite::MenuInfoGetByName( _T("Default") ) ->GetNode( true );
CExtCustomizeCmdTreeNode * pMenuNodeCustomized =
CExtCustomizeSite::MenuInfoGetByName( _T("Default") ) ->GetNode( false );
// changing command tree structure of the pMenuNodeInitial node
. . .
// reset initially customized menu state:
*pMenuNodeCustomized = *pMenuNodeInitial;

Customize Site is initialized with data associated with this frame window. The necessary commands are registered in it:

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

Persistent states of the customization subsystem and control bars are restored. Typically, these operations are final in the OnCreate() method of the frame window:

CExtCustomizeSite::CustomizeStateLoad(
pApp->m_pszRegistryKey,
pApp->m_pszProfileName,
pApp->m_pszProfileName
);
if( !CExtControlBar::ProfileBarStateLoad(
this,
pApp->m_pszRegistryKey,
pApp->m_pszProfileName,
pApp->m_pszProfileName,
&m_dataFrameWP))
{
DockControlBar( &m_wndMenuBar );
DockControlBar( &m_wndToolBarStandard );
. . .
RecalcLayout();
}
return 0;
}

Finally, you should put the code for storing the UI state into the DestroyWindow() method of the main frame window:

BOOL CMainFrame::DestroyWindow() {
CWinApp * pApp = ::AfxGetApp();
ASSERT( pApp != NULL );
ASSERT( pApp->m_pszRegistryKey != NULL );
ASSERT( pApp->m_pszRegistryKey[0] != _T('\0') );
ASSERT( pApp->m_pszProfileName != NULL );
ASSERT( pApp->m_pszProfileName[0] != _T('\0') );
VERIFY(
CExtCustomizeSite::CustomizeStateSave(
pApp->m_pszRegistryKey,
pApp->m_pszProfileName,
pApp->m_pszProfileName)
);
VERIFY(
CExtControlBar::ProfileBarStateSave(
this,
pApp->m_pszRegistryKey,
pApp->m_pszProfileName,
pApp->m_pszProfileName)
);
VERIFY(
g_CmdManager->SerializeState(
pApp->m_pszProfileName,
pApp->m_pszRegistryKey,
pApp->m_pszProfileName,
true)
);
g_CmdManager->ProfileWndRemove( GetSafeHwnd() );
return CFrameWnd::DestroyWindow();
}