This article describes one implementation of the selection bar which is present in Microsoft's applications for the PocketPC 2002. After looking very thoroughly through the PPC 2002 SDK, I found no API that would implement this functionality, so I decided to implement it myself.
The selection bar is implemented through the
CCeSelectBar class, derived from MFC's own
CControlBar. In this first approach to the selection bar implementation, I chose to allow only for menus to be displayed when the user clicks one of the two available selections. These are either on the top left or on the top right. Each selection is defined in terms of a menu (
CMenu*), one title string, one option string and an optional icon.
Each menu is identified by the integers 0 for the left, and 1 for the right. These should be used in all methods that have an
nPos parameter. This is not a very sophisticated approach, but you can be sure that the debug version will assert, should you fail on this.
The title string is displayed when the menu is active (see the right selection on the picture) and does not typically change during the execution of the program. The option string is displayed when the menu is not active, and is meant to inform the user of what option is currently selected. The icon should be 16 x 16 pixels and can be changed anytime, possibly as a response to a user's selection.
This bar can only live attached to the top and has a fixed height.
Using the Selection Bar
CControlBar-derived class, you should create it in your
CMainFrame::OnCreate() method, like in the demo project. This project uses
CChildView::SetSelectBar() in order to have the child view know the selection bar. In fact, it is the child view the one that is responsible for instancing both left and right menus and to process their states, and the setup of both menus is done in this method.
The menu command handlers, besides displaying the selected option in a message box, also set up the option string and the menu state through
Clearing a Menu
If during the course of your application you need to clear one of the menus, use the
Replacing a Menu
Any one of the two menus can be replaced at any time using the initialization process as shown in the demo project. Please notice that managing the
CMenu objects is your responsibility, not the bar's.
Look and Feel
I tried very hard to make this bar both look and operate like the ones Microsoft has implemented in its applications. The problem is that even they seem to be doing this differently in each application. Just look at how they do it in File Explorer and in the Inbox. I chose to copy the first one's look and feel.