Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Button with ToolTip and/or Bitmap Resource

0.00/5 (No votes)
14 Oct 2001 1  
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:
    #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:
    // 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:
    #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:
    // 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.

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