Microsoft WORD 2007 Style Semi-transparent Minibar






4.96/5 (13 votes)
Create a very basic Microsoft WORD 2007 style semi-transparent Minibar with tooltip like behaviour
Introduction
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.
Background
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 CMiniToolBarDlg.
All you have to do is declare a variable of the class CMiniToolBarDlg
, and initialize it using the Create
API.
CMiniToolBarDlg minibar;
minibar.Create();
Then of course, you have to set the Hover Window (upon which the mini bar should be shown) through SetHoverWindow
API call.
minibar.SetHoverWindow(pViewWindow);
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.
minibar.SetHoverRect(rcHoverRect)
And lastly call the Activate
API upon receiving WM_MOUSEMOVE
event on the hover window, i.e., call Activate
inside OnMouseMove
.
minibar.Activate(ptMousePoint)
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 SetHoverWindow
inside OnMouseMove
just before calling Activate()
.
Sample Code at a Glance
// CMyView is a view derived from CView in an MFC Doc/View Application
class CMyView : public CView
{
……
public:
// constructor
CMyView()
{
// Set the minibar pointer to NULL
m_pMiniBar = NULL;
}
…..
// definition of the mouse move message handler of the view
afx_msg void OnMouseMove(UINT nFlags, CPoint point)
{
// Instantiate and create only once in a convenient place
// It could have been also created in the OnInitialUpdate() method
if(m_pMiniBar == NULL)
{
m_pMiniBar = new CMiniToolBarDlg();
}
if(m_pMiniBar != NULL && m_pMiniBar->GetSafeHwnd() == NULL)
{
m_pMiniBar->Create();
}
// Invoke the minibar after m_pMiniBar->GetDelayTime() ms elapsed
m_pMiniBar->Activate(point);
…..
CView::OnMouseMove(nFlags, point);
}
};
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 classCMiniToolBarBase
. It resides in the top of the hierarchy from whereCMiniToolBarDlg
is inherited from. Therefore this behaviour can be applied to any window class that is derived fromCMiniToolbarBase
and implements the pure virtual overrideGetMiniToolBarWnd
and relays the mouse events to the base class following the methodology ofCMiniToolBarDlg
. - 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
andCCommandButtonTheme
. 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.
Acknowledgements
- 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.
History
- Article posted on June 23, 2010