News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How can I use a command bar in a dialog?

By Vassili Philippov, September 06, 2001.
Print version

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

Create necessary resources
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

Result dialog based application
You could download sample dialog based application that illustrates working with a command bar. DialogCommandBar.zip (48 Kb).

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House