Click here to Skip to main content
11,933,905 members (54,564 online)
Click here to Skip to main content
Add your own
alternative version


101 bookmarked

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


    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!


    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

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

    You may also be interested in...

    Comments and Discussions

    QuestionEnable/Disable Issue with IE9 Pin
    HydGuy31-Jan-12 4:48
    memberHydGuy31-Jan-12 4:48 
    GeneralFIX: m_ToolTip.AddTool() with correct button size [modified] Pin
    Christoph Conrad26-Jul-10 1:57
    memberChristoph Conrad26-Jul-10 1:57 
    GeneralText "Click me" not shown Pin
    the Jimmy21-Feb-07 21:10
    memberthe Jimmy21-Feb-07 21:10 
    First of all, this is very nice. This is something I've been looking for.

    I checked this out, it works well except some small problem, at least this is what I observed. I hope someone could fine tune this Hoverbutton to correct this.

    The text "click me" show when the mouse move over the button, this works everytime as long as you don't wait for awhile until the text "click me" disappeared by itself.

    The problem I see is that once the text "click me" disappeared, move the mouse over the button again will not guaranty the text "click me" will be shown again. I had to click somewhere on the desktop, then click on the Hover window again, then moving the mouse over the button, then "click me" will show again.

    Thanks in advance.


    GeneralRe: Text "Click me" not shown Pin
    yjnevergone5-Apr-09 6:36
    memberyjnevergone5-Apr-09 6:36 
    Generaltext over bitmap Pin
    tyounsi2-Jan-07 15:07
    membertyounsi2-Jan-07 15:07 
    Generalload image from file [modified] Pin
    a.damm7-Aug-06 22:51
    membera.damm7-Aug-06 22:51 
    GeneralTransparent bitmaps Pin
    Gismow26-Jul-06 23:10
    memberGismow26-Jul-06 23:10 
    Generalplz help me to solve tis problem with getting Front Page 98’s hover buttons to function. Pin
    ac sakura7-Jul-06 2:59
    memberac sakura7-Jul-06 2:59 
    Generalu r experiencing problem with getting Front Page 98's Hover buttons to fuction Pin
    ac sakura7-Jul-06 2:53
    memberac sakura7-Jul-06 2:53 
    GeneralSlightly Off Topic Pin
    69 Bay4-Jul-06 7:26
    member69 Bay4-Jul-06 7:26 

    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.

    | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.151126.1 | Last Updated 13 Oct 2000
    Article Copyright 2000 by Niek Albers
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid