Choice Bar control

Choice Bar control

This article was submitted .

When poking around on the web I found this nice MFC control in the Ultimate Toolbox library from Dundas. It's a generic control that eases the development of popup bars. Most of the current popup bars found in applications today follow a "choose a button from a list of different buttons" form and can be generalized into a control template.
I thought it was a nice abstraction that relieves the programmer from messing with button frames, hover effects and layout code - so I wrote a similar control for WTL.

The control is divided into 3 parts: The Default button, the button grid and the Custom button area. The Default and Custom buttons are optional.
You must develop your own control and derive from CChoiceBarCtrl to make use of it, or you can handle the custom drawing of the buttons in the parent window. Graceful WM_DRAWITEM messages are sent out in request to the parent to draw each of the button faces, but the layout and button frames (including hover effects) are handled by the control.
The number of buttons is decided by member methods and the layout is determined by setting the preferred number of columns. In addition, you can change the padding between buttons and the button style.
Tooltips are supported, but they can be very tricky to get right because the WTL Framework classes either tend to eat reflected TTN_GETDISPINFO notification messages or reject them.

How to use it

To add a Choice Bar control to your frame window, create a new derived control or handle the WM_DRAWITEM in your parent window.
A few sample controls are included in the source file.

To add the sample Palette Chooser control shown above as a popup in your application, add a reference to the CPaletteSelectCtrl control class.

  CPaletteSelectCtrl m_wndPS;
Add the following reflection macro to your main message map:
Then in a tool button click event, or where you wish to display the bar, add this...
  LRESULT OnEvent(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM ...
    m_wndPS.Create(m_hWnd, rc, NULL, WS_POPUP | WS_DLGFRAME);
The control resizes itself to its preferred size, but uses the supplied rectangle to position itself. As a true popup bar, it destroys itself when it looses focus even though this feature can be disabled.
When something is selected, you will receive a WM_NOTIFY notification with the CHBN_ITEMSELECTED code. The control sends out a few more notifications to allow you to further customize each control.

The Choice Bar does not include a matching dropdown button. You can choose to create your own, or, if you display the control from a toolbar button, use the dropdown capabilities of the toolbar.

Source Code Dependencies

Microsoft WTL 3.0 Library

Useful Links

Dundas software MFC Toolbox

Download Files

DownloadSource Code (8 Kb)

To the top