5,445,109 members and growing! (14,702 online)
Email Password   helpLost your password?
Desktop Development » Button Controls » Owner-draw buttons     Intermediate

Button with ToolTip and/or bitmap resource

By Jean-Louis Guenego

A simple way to have tooltip and a 4 state button using a bitmap resource
VC6, C++Windows, NT4, Win2K, MFC, VS6, Visual Studio, Dev

Posted: 14 Oct 2001
Updated: 14 Oct 2001
Views: 98,896
Bookmarked: 27 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
9 votes for this Article.
Popularity: 4.29 Rating: 4.50 out of 5
1 vote, 14.3%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
2 votes, 28.6%
4
4 votes, 57.1%
5

Sample Image - ToolTipRessourceButton.gif

Introduction

This article is inspired from the HoverButton found at CodeProject. Thanks to its author Niek Albers. You should read it before what follow. 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 this steps :

  1. First you need the 2 following files:

    • ToolTipButton.cpp
    • ToolTipButton.h

    Insert these 2 files in your project.

  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

About the Author

Jean-Louis Guenego


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.
Location: United States United States

Other popular Button Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 12 of 12 (Total in Forum: 12) (Refresh)FirstPrevNext
Subject  Author Date 
Generalno tooltip in cdialogbarmembersonic2922:46 17 Aug '05  
GeneralExample causes memory leaksmemberOgi1:03 27 Aug '04  
Generals Using this Button in Dialog Barmemberiffi9923:00 14 Jan '04  
GeneralCan we apply bitmap buttons at runtime?memberc_anands1:26 28 Feb '03  
GeneralToolTipButton in modeless Dialogsmemberjensieleinchen3:10 12 Jun '02  
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...)memberfrankym11:12 30 Oct '03  
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...)memberhroenick9:52 6 Jan '05  
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...)memberfrankym12:36 7 Jan '05  
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...)memberhroenick12:52 7 Jan '05  
GeneralRe: ToolTipButton in modeless Dialogs (in any non CFrameWnd container...)memberJPMSODENA23:31 9 May '07  
GeneralProblemsmemberYasmin7:49 26 Mar '02  
GeneralRe: Problems [modified]member__sephiroth5:41 14 Sep '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 14 Oct 2001
Editor: Chris Maunder
Copyright 2001 by Jean-Louis Guenego
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project