Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Microsoft WORD 2007 Style Semi-transparent Minibar

, 29 Jun 2010
Rate this:
Please Sign up or sign in to vote.
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

  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)

Share

About the Author

Mukit, Ataul
Chief Technology Officer Rational Technologies
Bangladesh Bangladesh
You don't learn patterns, you just code it.
Follow on   Twitter

Comments and Discussions

 
GeneralThis is a decent start, but... PinmvpDave Kreskowiak23-Jun-10 1:23 
GeneralRe: This is a decent start, but... PinmemberMukit, Ataul29-Jun-10 19:50 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 29 Jun 2010
Article Copyright 2010 by Mukit, Ataul
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid