COXPopupBarCtrl General Information

Copyright © The Code Project 1997 - 1998, All Rights Reserved

Our Popup Bar control as any control that can be represented as a top most popup window with items on it that can be chosen using the mouse or keyboard. For example standard Popup Menu Bar or Color Picker from Word 97 are Popup Bar controls. Next types of items can be defined on  our Popup Bar control :

"Default" button. Always is located on the top. The size of this button is calculated automatically.
"Common" buttons. You can set the number of common buttons and their size. You can also set the number of rows used to display them. 
"Custom" button. Is always located at the bottom. Size of this button is calculated automatically.

Default and Custom buttons are optional and at least one common button has to be assigned to the Popup Bar control.

After displaying, the Popup Bar control captures all mouse messages and hides itself if any mouse button is clicked or the user presses ESC, ENTER or SPACE buttons. If at the moment of clicking the mouse wasn't over any button within Popup Bar or user pressed ESC then nothing was chosen.

COXPopupBarCtrl is a generic class designed specifically as a base class to provide basic functionality of any Popup Bar control. 

Next are the main points about this class: 

With any button (except Custom button) we associate DWORD value to uniquely identify them. In derived class you specify the logic of this value. It can be just a plain value or a pointer to any object, but it's up to implementor to provide logic that stands by that value. 

COXPopupBarCtrl is created in two steps: constructor and Create function. In constructor you can specify number of common buttons, number of rows to display common buttons, common button size, the value that should be associated with Default button and the text that is going to be displayed on Default and Custom buttons.
After creation you can change whatever attributes you want (including those specified in the constructor and Create function)

In order to provide graphical representation of buttons in your derived class, you will probably need to overwrite the following virtual functions:

virtual void DrawButton(CDC* pDC, UINT nIndex);
virtual void DrawDefaultButton(CDC* pDC);
virtual void DrawCustomButton(CDC* pDC);
virtual void DrawFrameRect(CDC* pDC, CRect& rect, UINT nIndex);

pDC - device context to draw in
nIndex - index of button to be drawn

When the Custom button is pressed next virtual function is called:

virtual BOOL OnCustomButton();

Override it too in order to provide your own handling of custom button in derived class.