This article is about creating a very simple MS_WORD 2007 style Minibar (the semi transparent bar that pops up when you select some text in Microsoft WORD). But the classes and the concepts used here can be extended to make any type of fancy Microsoft OFFICE style toolbars.
I have been working on a Framework application for a few years, one part of which is to provide customized GUI elements like Control Bars, Tool Bars, Caption Bars, List Views, Frame Windows and dialogs with caption buttons, etc.
So, I had to write some generic classes that can be used specially for control/tool/dialog bars and caption bars to show buttons with customized look and feel.
A recent requirement was to develop a Minibar which pops up when the mouse stays still on a specified hover area. Since I already had these set of generic classes to show toolbar buttons (which actually is just a drawing), I used them to easily implement the Minibar. I only had to write a few more lines of codes to invoke a timer and show the minibar after a certain amount of time has elapsed.
Using the Code
Using the code is pretty much simple.
Here, the main class to use is
All you have to do is declare a variable of the class
CMiniToolBarDlg, and initialize it using the
Then of course, you have to set the Hover Window (upon which the mini bar should be shown) through
SetHoverWindow API call.
You can also set a hover area for the minibar by calling
SetHoverRect API. If it is not called, then the whole client area of the hover window is considered to be the hover rect.
And lastly call the
Activate API upon receiving
WM_MOUSEMOVE event on the hover window, i.e., call
In the source code uploaded, I have actually used a single minibar control throughout the whole application. Upon receiving mouse move event of the focused window, I change the hover window by calling
OnMouseMove just before calling
Sample Code at a Glance
class CMyView : public CView
m_pMiniBar = NULL;
afx_msg void OnMouseMove(UINT nFlags, CPoint point)
if(m_pMiniBar == NULL)
m_pMiniBar = new CMiniToolBarDlg();
if(m_pMiniBar != NULL && m_pMiniBar->GetSafeHwnd() == NULL)
Points of Interest
- The popping up behaviour on mouse stall for a few milliseconds (which can be set by calling
SetDelayTime API of the minibar) has been implemented in the base class
CMiniToolBarBase. It resides in the top of the hierarchy from where
CMiniToolBarDlg is inherited from. Therefore this behaviour can be applied to any window class that is derived from
CMiniToolbarBase and implements the pure virtual override
GetMiniToolBarWnd and relays the mouse events to the base class following the methodology of
- Although the main topic here is about the Microsoft WORD style minibar, but the classes used to show the minibar buttons can be reused for development of any kind of command/caption/tool bar. For example, if you compile and run the source uploaded, you will see a collapsible button on the caption bar of a view (it will not appear in Windows Vista or Windows 7 since those O/Ss doesn't support non client area drawing the usual way) and that too using the same classes used for showing the minibar buttons. These classes are namely
CCommandBarObj, CCommandButtonObj and
CCommandButtonTheme. You can inherit from and override the virtual functions of these classes to create any type of Bars and give any type of look and feel.
- Paul Dilascia for his extremely fun to read but informative articles.
- Chris Maunder for his
CGridCtrl class which helped me learn GUI programming and design tactics.
- Jacques Raphanel for his inspiring work on GUI controls that helped me improve with GUI controls development and design.
- Article posted on June 23, 2010