Menu
Menu
The CMainFrame should inherit from CXTPMDIFrameWnd.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Create Status bar.
// Important: All control bars including the Status Bar
// must be created before CommandBars....
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// Initialize the command bars
if (!InitCommandBars())
return -1;
// Get a pointer to the command bars object.
CXTPCommandBars* pCommandBars = GetCommandBars();
if(pCommandBars == NULL)
{
TRACE0("Failed to create command bars object.\n");
return -1; // fail to create
}
// Add the menu bar
CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
_T("Menu Bar"), IDR_MDISAMTYPE);
if(pMenuBar == NULL)
{
TRACE0("Failed to create menu bar.\n");
return -1; // fail to create
}
// Create ToolBar
CXTPToolBar* pToolBar = (CXTPToolBar*)
pCommandBars->Add(_T("Standard"), xtpBarTop);
if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
// Set Office 2003 Theme
CXTPPaintManager::SetTheme(xtpThemeOffice2003);
return 0;
}
Customization Toolbars
//MainFrm.h
afx_msg void OnClose();
afx_msg void OnCustomize();
//MainFrm.cpp
ON_WM_CLOSE()
ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
void CMainFrame::OnCustomize()
{
// Get a pointer to the command bars object.
CXTPCommandBars* pCommandBars = GetCommandBars();
if(pCommandBars != NULL)
{
// Instanciate the customize dialog object.
CXTPCustomizeSheet dlg(pCommandBars);
// Add the options page to the customize dialog.
CXTPCustomizeOptionsPage pageOptions(&dlg);
dlg.AddPage(&pageOptions);
// Add the commands page to the customize dialog.
CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage();
pCommands->AddCategories(IDR_MDISAMTYPE);
// Use the command bar manager to initialize the
// customize dialog.
pCommands->InsertAllCommandsCategory();
pCommands->InsertBuiltInMenus(IDR_MDISAMTYPE);
pCommands->InsertNewMenuCategory();
// Dispaly the dialog.
dlg.DoModal();
}
}
//Load settings from configuration file
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
// Load the previous state for toolbars and menus.
LoadCommandBars(_T("CommandBars"));
return 0;
}
//Save settings to configuration file.
void CMainFrame::OnClose()
{
// Save the current state for toolbars and menus.
SaveCommandBars(_T("CommandBars"));
CMDIFrameWnd::OnClose();
}
Intelligent Menus
static UINT uHideCmds[] =
{
ID_FILE_PRINT, ID_FILE_PRINT_PREVIEW, ID_WINDOW_CASCADE
};
//CMainFrame::OnCreate()
// Hide array of commands
pCommandBars->HideCommands(uHideCmds, _countof(uHideCmds));
// Set "Always Show Full Menus" option to the FALSE
CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();
pOptions->bAlwaysShowFullMenus = FALSE;