Click here to Skip to main content
15,881,089 members
Articles / Desktop Programming / MFC

Button with ToolTip and/or Bitmap Resource

Rate me:
Please Sign up or sign in to vote.
4.57/5 (8 votes)
14 Oct 20012 min read 173.7K   4.6K   54   14
A simple way to have tooltip and a 4 state button using a bitmap resource

Sample Image - ToolTipRessourceButton.gif

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:

  1. tooltip control (except when disabled)
  2. possible bitmap representation with 4 states like CBitmapButton (up, down, focused, disabled)

The difference with the HoverButton is that:

  1. we have the possibility to DISABLE the button
  2. we can use the tooltip and bitmap functionalities separately

There are two classes involved here:

  1. CToolTipButton: It is a CButton with only the tooltip functionality
  2. 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.

  1. First, you need the 2 following files:
    • ToolTipButton.cpp
    • ToolTipButton.h
  2. Include in the dialog where you want to use the buttons:
    C++
    #include "ToolTipButton.h"
  3. With the ClassWizard (menu Member Variable), add a control attributes for the button.
  4. Modify in the code the button class control CButton to CToolTipButton.
  5. In the method OnInitDialog(), add the following code:
    C++
    // TODO: Add extra initialization here
    // The only code to setup the button
    // IDB_TOOLTIP_RESSOURCE_BUTTON is the bitmap resource ID
    m_ToolTipButton.SetToolTipText(new CString("hello !!!"));
    

and that should be it.

How to Use It (All the Functionality)

  1. First, you need the 4 following files:
    1. ToolTipButton.cpp
    2. ToolTipButton.h
    3. ToolTipRessourceButton.cpp
    4. ToolTipRessourceButton.h

    Insert these 4 files in your project.

  2. Include in the dialog where you want to use the buttons:
    C++
    #include "ToolTipRessourceButton.h"
  3. Make a bitmap resource with the 4 states like this one:

    Bitmap ressource

  4. Add the bitmap in the resources (import):
  5. With the ClassWizard (menu Member Variable), add a control attributes for the button.
  6. Modify in the code the button class control CButton to CToolTipRessourceButton.
  7. In the method OnInitDialog(), add the following code:
    C++
    // TODO: Add extra initialization here
    // The only code to setup the button
    // IDB_TOOLTIP_RESSOURCE_BUTTON is the bitmap resource ID
    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.


Written By
United States United States
Professor in physics at Universty of Marne-La-Vallee (Paris, France).
Ex-Consultant (in Telecom) for Cap Gemini America at Atherton (Silicon Valley, San Francisco, CA USA).
I like very much coding.

Comments and Discussions

 
GeneralUsing CWnd::EnableToolTips() [modified] Pin
Rolf Kristensen18-Mar-09 0:55
Rolf Kristensen18-Mar-09 0:55 
Generalno tooltip in cdialogbar Pin
sonic2917-Aug-05 21:46
sonic2917-Aug-05 21:46 
GeneralExample causes memory leaks Pin
Ogi27-Aug-04 0:03
Ogi27-Aug-04 0:03 
Generals Using this Button in Dialog Bar Pin
iffi99214-Jan-04 2:00
iffi99214-Jan-04 2:00 
QuestionCan we apply bitmap buttons at runtime? Pin
c_anands28-Feb-03 0:26
c_anands28-Feb-03 0:26 
GeneralToolTipButton in modeless Dialogs Pin
jensieleinchen12-Jun-02 2:10
jensieleinchen12-Jun-02 2:10 
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...) Pin
kwehfu30-Oct-03 10:12
kwehfu30-Oct-03 10:12 
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...) Pin
hroenick6-Jan-05 8:52
hroenick6-Jan-05 8:52 
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...) Pin
kwehfu7-Jan-05 11:36
kwehfu7-Jan-05 11:36 
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...) Pin
hroenick7-Jan-05 11:52
hroenick7-Jan-05 11:52 
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...) Pin
JPMSODENA9-May-07 22:31
JPMSODENA9-May-07 22:31 
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...) Pin
Hieupv20006-Oct-08 1:34
Hieupv20006-Oct-08 1:34 
GeneralProblems Pin
26-Mar-02 6:49
suss26-Mar-02 6:49 
GeneralRe: Problems [modified] Pin
Devil's Priest14-Sep-06 4:41
Devil's Priest14-Sep-06 4:41 

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.