Click here to Skip to main content
15,867,453 members
Articles / Desktop Programming / MFC

Microsoft WORD 2007 Style Semi-transparent Minibar

Rate me:
Please Sign up or sign in to vote.
4.96/5 (13 votes)
29 Jun 2010CPOL3 min read 33.7K   815   18   4
Create a very basic Microsoft WORD 2007 style semi-transparent Minibar with tooltip like behaviour
Image 1

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.

C++
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.

C++
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.

C++
minibar.SetHoverRect(rcHoverRect) 

And lastly call the Activate API upon receiving WM_MOUSEMOVE event on the hover window, i.e., call Activate inside OnMouseMove.

C++
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

C++
// 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

  1. 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 CMiniToolBarDlg.
  2. 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.

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1

Comments and Discussions

 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey26-Feb-12 20:52
professionalManoj Kumar Choubey26-Feb-12 20:52 
GeneralThis is a decent start, but... Pin
Dave Kreskowiak23-Jun-10 1:23
mveDave Kreskowiak23-Jun-10 1:23 
GeneralRe: This is a decent start, but... Pin
Mukit, Ataul29-Jun-10 19:50
Mukit, Ataul29-Jun-10 19:50 
GeneralComments Pin
Md. Marufuzzaman22-Jun-10 23:48
professionalMd. Marufuzzaman22-Jun-10 23:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.