QA: How can I use a command bar in a dialog?
Vassili Philippov (vasja@spbteam.com), September 06, 2001.
Question
I write a dialog based application. How can I use a command bar in it? I need a
menu and a toolbar.
Answer
CDialog class has a child command bar control. It is strange but you will not
find information about it in the documentation. Nevertheless if you look at sources
you will find:
protected:
CControlBar* m_pWndEmptyCB;
You could downcast this control to CCeCommandBar it will work. This control is
already initialized, so the answer will be "Use m_pWndEmptyCB member variable".
Step by step
Step 1

First of all create necessary resources. Usualy they are a toolbar and a menu bar.
Step 2
Fill m_pWndEmptyCB command bar with necessary elements in OnInitDialog method. Look at
methods of CCeCommandBar to understand what you can do. You can insert menu, toolbar,
buttons, combo boxes, etc. One thing you should keep in mind: after some operations
CCeCommandBar forgets correct button sizes and you should call SetSizes method to
restore them. Here is a sample code:
BOOL CDialogCommandBarDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
CCeCommandBar *pCommandBar = (CCeCommandBar*)m_pWndEmptyCB;
pCommandBar->LoadToolBar(IDR_MYTOOLBAR);
pCommandBar->InsertMenuBar(IDR_MYMENUBAR);
pCommandBar->SetSizes(CSize(23,21), CSize(16,15));
return TRUE; // return TRUE unless you set the focus to a control
}
Result

You could download sample dialog based application that illustrates working
with a command bar. DialogCommandBar.zip (48 Kb).
Related resources:
-
http://www.pocketpcdn.com/sections/ui.html
Section: User Interface
-
http://www.pocketpcdn.com/articles/cmdbar_menu.html
QA: How do I get the command bar menu handle?
-
http://www.pocketpcdn.com/articles/second_commandbar.html
QA: How can I implement the second toolbar like the one in Pocket Word?
-
http://www.pocketpcdn.com/articles/updatecommandui.html
QA: Why ON_UPDATE_COMMAND_UI handlers get called again and again?
-
http://www.pocketpcdn.com/articles/remove_new_button.html
QA: How to remove New button from command bar?