Introduction
This article is inspired from the HoverButton found at Code Project. Thanks to its author, Niek Albers. You should read it before what follows. With the two classes presented here, you can easily use button controls which have:
- tooltip control (except when disabled)
- possible bitmap representation with 4 states like
CBitmapButton
(up, down, focused, disabled)
The difference with the HoverButton
is that:
- we have the possibility to DISABLE the button
- we can use the tooltip and bitmap functionalities separately
There are two classes involved here:
CToolTipButton
: It is a CButton
with only the tooltip functionality CToolTipRessourceButton
: It is a CToolTipButton
with bitmap representation (4 states)
How to Use It (Tooltip Functionality Only)
If you want only the tooltip functionality, follow these steps:
Insert these 2 files in your project.
- First, you need the 2 following files:
- ToolTipButton.cpp
- ToolTipButton.h
- Include in the dialog where you want to use the buttons:
#include "ToolTipButton.h"
- With the
ClassWizard
(menu Member Variable), add a control attributes for the button. - Modify in the code the button class control
CButton
to CToolTipButton
. - In the method
OnInitDialog()
, add the following code:
m_ToolTipButton.SetToolTipText(new CString("hello !!!"));
and that should be it.
How to Use It (All the Functionality)
- First, you need the 4 following files:
- ToolTipButton.cpp
- ToolTipButton.h
- ToolTipRessourceButton.cpp
- ToolTipRessourceButton.h
Insert these 4 files in your project.
- Include in the dialog where you want to use the buttons:
#include "ToolTipRessourceButton.h"
- Make a bitmap resource with the 4 states like this one:
- Add the bitmap in the resources (import):
- With the
ClassWizard
(menu Member Variable), add a control attributes for the button. - Modify in the code the button class control
CButton
to CToolTipRessourceButton
. - In the method
OnInitDialog()
, add the following code:
m_ToolTipRessourceButton.LoadBitmap(IDB_TOOLTIP_RESSOURCE_BUTTON);
m_ToolTipRessourceButton.SetToolTipText(new CString("hello !!!"));
and that should be it.
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found here.