Click here to Skip to main content
Click here to Skip to main content

CHoverButton - A simple hoverbutton with one bitmap and a tooltip

By , 12 Oct 2000
 
  • Download demo project - 16 Kb
  • 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

    About the Author

    Niek Albers
    Web Developer
    Netherlands Netherlands
    Member
    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.

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    QuestionEnable/Disable Issue with IE9memberHydGuy31 Jan '12 - 3:48 
    GeneralFIX: m_ToolTip.AddTool() with correct button size [modified]memberChristoph Conrad26 Jul '10 - 0:57 
    GeneralText "Click me" not shownmemberthe Jimmy21 Feb '07 - 20: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.
     
    Jim

    GeneralRe: Text "Click me" not shownmemberyjnevergone5 Apr '09 - 5:36 
    Generaltext over bitmapmembertyounsi2 Jan '07 - 14:07 
    Generalload image from file [modified]membera.damm7 Aug '06 - 21:51 
    GeneralTransparent bitmapsmemberGismow26 Jul '06 - 22:10 
    Generalplz help me to solve tis problem with getting Front Page 98’s hover buttons to function.memberac sakura7 Jul '06 - 1:59 
    Generalu r experiencing problem with getting Front Page 98's Hover buttons to fuctionmemberac sakura7 Jul '06 - 1:53 
    GeneralSlightly Off Topicmember69 Bay4 Jul '06 - 6:26 
    Generaltooltipsmemberramyasangeet8 Mar '06 - 21:52 
    Generaldinamic creationmemberMax Santos8 Feb '06 - 14:09 
    GeneralButton Not Showing upmembertweetpiyo6 Feb '06 - 7:15 
    GeneralMinor improvement - transparent backgroundmemberHans Dietrich5 Sep '04 - 9:11 
    GeneralRe: Minor improvement - transparent backgroundmemberAnne Jan Beeks25 Jun '05 - 3:32 
    GeneralRe: Minor improvement - transparent backgroundmemberSims11 Aug '05 - 0:36 
    GeneralRe: Minor improvement - transparent backgroundmembernewofilms7 Dec '05 - 15:04 
    GeneralButton as Hyperlink in MFCmemberSunilJoshi_MCA24 Mar '04 - 1:59 
    GeneralSomething maybe better!memberTailor28 Feb '04 - 21:06 
    GeneralProblem compiling example in VC++ 7memberSick@work4 Nov '03 - 2:34 
    GeneralRe: Problem compiling example in VC++ 7sussHJ Jo12 Dec '03 - 1:57 
    GeneralRe: Problem compiling example in VC++ 7memberJust_a_girl15 May '04 - 22:58 
    GeneralRe: Problem compiling example in VC++ 7memberihawley19 Jul '04 - 22:58 
    GeneralTrackMouseEventmembershinay19 Jul '03 - 11:57 
    GeneralRe: TrackMouseEventsussAnonymous25 Aug '03 - 22:04 
    GeneralRe: TrackMouseEventsussAnonymous25 Aug '03 - 22:04 
    Generalmybitmap.detach() missing in CHoverButton::LoadImage()memberRhettLiu12 Jul '03 - 21:35 
    GeneralRe: mybitmap.detach() missing in CHoverButton::LoadImage()sussAnonymous4 Jan '04 - 8:13 
    GeneralProblemmemberWu Mintao14 Jun '03 - 8:43 
    GeneralRe: ProblemsussRob T.25 Jun '03 - 9:45 
    GeneralRe: ProblemmemberWu Mintao26 Jun '03 - 3:02 
    GeneralThanks for the _TrackMouseEvent ...memberMaximilien6 Dec '02 - 4:54 
    GeneralPROBLEM!!sussAnonymous10 Oct '02 - 4:04 
    GeneralHover Button problemmemberAnonymous11 Feb '02 - 23:12 
    GeneralRe: Hover Button problemmemberthanh200222 Oct '02 - 7:02 
    GeneralRe: Hover Button problemmemberac sakura7 Jul '06 - 2:04 
    Generalinformationmemberkashif gulzar23 Dec '01 - 9:34 
    GeneralProblem with CHoverButton::LoadBitmap in Netscape Plugin (DLL)memberAnonymous5 Nov '01 - 17:21 
    GeneralRe: Problem with CHoverButton::LoadBitmap in Netscape Plugin (DLL)memberHappy Bob16 Nov '01 - 9:49 
    GeneralRe: Problem with CHoverButton::LoadBitmap in Netscape Plugin (DLL)sussAnonymous10 Oct '02 - 3:54 
    GeneralflickermemberWill12 Jul '01 - 11:27 
    GeneralRe: flickermemberJungsul Lee20 Aug '01 - 3:04 
    GeneralRe: flickermemberseikou12 Aug '04 - 23:38 
    GeneralHoverButton on FormViewmemberTim Matthews15 Jun '01 - 5:15 
    GeneralHover ButtonmemberAnonymous31 May '01 - 12:30 
    GeneralRe: Hover ButtonmemberMohammadj20 Mar '09 - 5:57 
    Generalhover buttonmemberAnonymous26 May '01 - 5:44 
    GeneralRe: hover buttonmemberPhilippe Lhoste22 Oct '01 - 2:36 
    GeneralPossible Bug.memberJulien9 May '01 - 14:57 
    GeneralRe: Possible Bug.memberEarl Rex Arao-arao10 May '01 - 22:10 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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