QA: How can I implement the second toolbar like one in Pocket Word?

Vassili Philippov (vasja@spbteam.com), April 02, 2003.

Question

I want to make two command bars in my application like it is implemented in Pocket Word. The second one should slide up automatically when SIP is shown. How can I do it?

Answer

Creating the second command bar is simple. Here is a sample code:

LPTSTR m_ToolTipsTable1[3]; m_ToolTipsTable1[0] = MakeString(IDS_TOOLTIP_1_1); m_ToolTipsTable1[1] = MakeString(IDS_TOOLTIP_1_2); m_ToolTipsTable1[2] = MakeString(IDS_TOOLTIP_1_3); CCeCommandBar *m_pCommandBar1; m_pCommandBar1 = new CCeCommandBar(); m_pCommandBar1->Create(this; m_pCommandBar1->InsertMenuBar(IDR_MYMENUBAR1); m_pCommandBar1->LoadToolBar(IDR_MYTOOLBAR1); m_pCommandBar1->SendMessage(TB_SETTOOLTIPS, (WPARAM)(4), (LPARAM)(m_ToolTipsTable1)); m_pCommandBar1->SetSizes(CSize(23,21), CSize(16,15));

A program with 3 command bars Now you have to move it to the right. To remove the unnecessary black frame from the left and right borders you should set the left coordinate of the command bar to -1 and the width to screen width + 2.

You should also remember about SIP when positioning the second command bar. If SIP is shown then the second command bar should be placed above it. You can use the SipGetInfo function to test if SIP is shown and to get its height.

The last thing you should worry about is moving the second command bar when SIP is shown or hidden. When SIP is shown or hidden your application receives a WM_SETTINGCHANGE message with wParam equal to SPI_SETSIPINFO. You should also check if SIP is shown or not and change the corresponding position of the command bar.

Sample

You can download a sample project that demonstrates working with three command bars - TestSecondToolbar.zip - 16 Kb. It contains a reusable CCommandBarSet class that you may use for your projects to organize several command bars. This class encapsulates logic of the command bar positioning.

Related resources: