Click here to Skip to main content
11,414,234 members (70,803 online)
Click here to Skip to main content

CHoverButton - A simple hoverbutton with one bitmap and a tooltip

, 12 Oct 2000
Rate this:
Please Sign up or sign in to vote.
A simple drop-in class that provides a 'hot' look button using the _TrackMouseEvent function
<!-- Download Links -->
  • Download demo project - 16 Kb
  • <!-- Article image -->

    Sample Image - hoverbutton.gif

    Introduction

    Looking around for some nice bitmap hover buttons, I just couldn't find what I was looking for. In this case there are a couple of things you can do:

    1. Leave it.
    2. Buy it.
    3. Steal it.
    4. Get it for free.
    5. Start crying
    6. Do it yourself (and possibly share it.)

    I'll share!

    I found another hoverbutton class that uses SetCapture() and ReleaseCapture(). Using this method gave me some problems. I can't remember why, but it did to me. So I thought why do it so difficult? MS has a nice API to handle hover states: _TrackMouseEvent().

    So here it is... The class. After a long thought i decided to call it: CHoverButton. I used some classes and information found elsewhere (thanks to the people for that).

    How to use it?

    1. In you resource editor create a button and set the 'owner draw' property.
    2. Use classwizard to create a CButton object in your dialog.
    3. Include the "hoverbutton.h" file in your dialog class file.
    4. Rename the CButton object type to CHoverButton.
    5. Create a bitmap with three buttonstates: Up/Down/Hover. The pictures need to be right next to each other.
      The button will calculate it's own size = (the width of the bitmap)/3.
      You can use true color bitmaps here. See below for an example image.
    6. In the OnInitDialog() load the bitmap with mybutton.LoadBitmap(IDC_MYBUTTON);
    7. Set a tooltip with mybutton.SetToolTipText();
    8. Compile and enjoy.

    Have fun!

    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

    Share

    About the Author

    Niek Albers
    Web Developer
    Netherlands Netherlands
    Niek is the founder and programmer of DaanSystems.com and is working on many projects all the time. He makes a living by doing contractwork for others.

    Comments and Discussions

     
    Generaltooltips Pin
    ramyasangeet, 8-Mar-06 22:52
    memberramyasangeet8-Mar-06 22:52 
    Generaldinamic creation Pin
    Max Santos, 8-Feb-06 15:09
    memberMax Santos8-Feb-06 15:09 
    GeneralButton Not Showing up Pin
    tweetpiyo, 6-Feb-06 8:15
    membertweetpiyo6-Feb-06 8:15 
    GeneralMinor improvement - transparent background Pin
    Hans Dietrich, 5-Sep-04 10:11
    memberHans Dietrich5-Sep-04 10:11 
    GeneralRe: Minor improvement - transparent background Pin
    Anne Jan Beeks, 25-Jun-05 4:32
    memberAnne Jan Beeks25-Jun-05 4:32 
    GeneralRe: Minor improvement - transparent background Pin
    Sims, 11-Aug-05 1:36
    memberSims11-Aug-05 1:36 
    GeneralRe: Minor improvement - transparent background Pin
    newofilms, 7-Dec-05 16:04
    membernewofilms7-Dec-05 16:04 
    GeneralButton as Hyperlink in MFC Pin
    SunilJoshi_MCA, 24-Mar-04 2:59
    memberSunilJoshi_MCA24-Mar-04 2:59 
    GeneralSomething maybe better! Pin
    Tailor, 28-Feb-04 22:06
    memberTailor28-Feb-04 22:06 
    GeneralProblem compiling example in VC++ 7 Pin
    Sick@work, 4-Nov-03 3:34
    memberSick@work4-Nov-03 3:34 
    GeneralRe: Problem compiling example in VC++ 7 Pin
    HJ Jo, 12-Dec-03 2:57
    sussHJ Jo12-Dec-03 2:57 
    GeneralRe: Problem compiling example in VC++ 7 Pin
    Just_a_girl, 15-May-04 23:58
    memberJust_a_girl15-May-04 23:58 
    GeneralRe: Problem compiling example in VC++ 7 Pin
    ihawley, 19-Jul-04 23:58
    memberihawley19-Jul-04 23:58 
    GeneralTrackMouseEvent Pin
    shinay, 19-Jul-03 12:57
    membershinay19-Jul-03 12:57 
    GeneralRe: TrackMouseEvent Pin
    Anonymous, 25-Aug-03 23:04
    sussAnonymous25-Aug-03 23:04 
    GeneralRe: TrackMouseEvent Pin
    Anonymous, 25-Aug-03 23:04
    sussAnonymous25-Aug-03 23:04 
    Generalmybitmap.detach() missing in CHoverButton::LoadImage() Pin
    RhettLiu, 12-Jul-03 22:35
    memberRhettLiu12-Jul-03 22:35 
    GeneralRe: mybitmap.detach() missing in CHoverButton::LoadImage() Pin
    Anonymous, 4-Jan-04 9:13
    sussAnonymous4-Jan-04 9:13 
    GeneralProblem Pin
    Wu Mintao, 14-Jun-03 9:43
    memberWu Mintao14-Jun-03 9:43 
    GeneralRe: Problem Pin
    Rob T., 25-Jun-03 10:45
    sussRob T.25-Jun-03 10:45 
    GeneralRe: Problem Pin
    Wu Mintao, 26-Jun-03 4:02
    memberWu Mintao26-Jun-03 4:02 
    GeneralThanks for the _TrackMouseEvent ... Pin
    Maximilien, 6-Dec-02 5:54
    memberMaximilien6-Dec-02 5:54 
    GeneralPROBLEM!! Pin
    Anonymous, 10-Oct-02 5:04
    sussAnonymous10-Oct-02 5:04 
    GeneralHover Button problem Pin
    Anonymous, 12-Feb-02 0:12
    memberAnonymous12-Feb-02 0:12 
    GeneralRe: Hover Button problem Pin
    thanh2002, 22-Oct-02 8:02
    memberthanh200222-Oct-02 8:02 
    GeneralRe: Hover Button problem Pin
    ac sakura, 7-Jul-06 3:04
    memberac sakura7-Jul-06 3:04 
    Generalinformation Pin
    kashif gulzar, 23-Dec-01 10:34
    memberkashif gulzar23-Dec-01 10:34 
    GeneralProblem with CHoverButton::LoadBitmap in Netscape Plugin (DLL) Pin
    Anonymous, 5-Nov-01 18:21
    memberAnonymous5-Nov-01 18:21 
    GeneralRe: Problem with CHoverButton::LoadBitmap in Netscape Plugin (DLL) Pin
    Happy Bob, 16-Nov-01 10:49
    memberHappy Bob16-Nov-01 10:49 
    GeneralRe: Problem with CHoverButton::LoadBitmap in Netscape Plugin (DLL) Pin
    Anonymous, 10-Oct-02 4:54
    sussAnonymous10-Oct-02 4:54 
    Generalflicker Pin
    Will, 12-Jul-01 12:27
    memberWill12-Jul-01 12:27 
    GeneralRe: flicker Pin
    Jungsul Lee, 20-Aug-01 4:04
    memberJungsul Lee20-Aug-01 4:04 
    GeneralRe: flicker Pin
    seikou, 13-Aug-04 0:38
    memberseikou13-Aug-04 0:38 
    GeneralHoverButton on FormView Pin
    Tim Matthews, 15-Jun-01 6:15
    memberTim Matthews15-Jun-01 6:15 
    GeneralHover Button Pin
    Anonymous, 31-May-01 13:30
    memberAnonymous31-May-01 13:30 
    GeneralRe: Hover Button Pin
    Mohammadj, 20-Mar-09 6:57
    memberMohammadj20-Mar-09 6:57 
    Generalhover button Pin
    Anonymous, 26-May-01 6:44
    memberAnonymous26-May-01 6:44 
    GeneralRe: hover button Pin
    Philippe Lhoste, 22-Oct-01 3:36
    memberPhilippe Lhoste22-Oct-01 3:36 
    GeneralPossible Bug. Pin
    Julien, 9-May-01 15:57
    memberJulien9-May-01 15:57 
    GeneralRe: Possible Bug. Pin
    Earl Rex Arao-arao, 10-May-01 23:10
    memberEarl Rex Arao-arao10-May-01 23:10 
    Generalhelp Pin
    zhang, 3-Apr-01 22:03
    memberzhang3-Apr-01 22:03 
    GeneralRe: help Pin
    Anonymous, 3-Apr-01 22:57
    memberAnonymous3-Apr-01 22:57 
    GeneralRe: help Pin
    Earl Rex Arao-arao, 10-May-01 23:37
    memberEarl Rex Arao-arao10-May-01 23:37 
    GeneralWindows 95 Pin
    Michael Groeger, 13-Dec-00 4:47
    memberMichael Groeger13-Dec-00 4:47 
    GeneralRe: Windows 95 Pin
    Anonymous, 19-Dec-00 3:53
    memberAnonymous19-Dec-00 3:53 
    GeneralRe: Windows 95 Pin
    Philippe Lhoste, 22-Oct-01 3:22
    memberPhilippe Lhoste22-Oct-01 3:22 
    GeneralBack ground Color of the button. Pin
    Neha, 1-Dec-00 22:39
    memberNeha1-Dec-00 22:39 
    GeneralRe: Back ground Color of the button. Pin
    Anonymous, 30-May-01 8:45
    memberAnonymous30-May-01 8:45 
    GeneralRe: Back ground Color of the button. Pin
    Philippe Lhoste, 22-Oct-01 3:27
    memberPhilippe Lhoste22-Oct-01 3:27 
    GeneralSeems pretty good. Pin
    D. Adams, 16-Oct-00 14:37
    sussD. Adams16-Oct-00 14:37 

    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 | Terms of Use | Mobile
    Web04 | 2.8.150427.2 | Last Updated 13 Oct 2000
    Article Copyright 2000 by Niek Albers
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid