Click here to Skip to main content
Licence 
First Posted 12 Oct 2000
Views 341,070
Bookmarked 99 times

CHoverButton - A simple hoverbutton with one bitmap and a tooltip

By | 12 Oct 2000 | Article
A simple drop-in class that provides a 'hot' look button using the _TrackMouseEvent function
  • 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

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    QuestionEnable/Disable Issue with IE9 PinmemberHydGuy3:48 31 Jan '12  
    GeneralFIX: m_ToolTip.AddTool() with correct button size [modified] PinmemberChristoph Conrad0:57 26 Jul '10  
    GeneralText "Click me" not shown Pinmemberthe Jimmy20:10 21 Feb '07  
    GeneralRe: Text "Click me" not shown Pinmemberyjnevergone5:36 5 Apr '09  
    Generaltext over bitmap Pinmembertyounsi14:07 2 Jan '07  
    It might be interesting to support overlay of text as well..
     
    Cheers
    Generalload image from file [modified] Pinmembera.damm21:51 7 Aug '06  
    GeneralTransparent bitmaps PinmemberGismow22:10 26 Jul '06  
    Generalplz help me to solve tis problem with getting Front Page 98’s hover buttons to function. Pinmemberac sakura1:59 7 Jul '06  
    Generalu r experiencing problem with getting Front Page 98's Hover buttons to fuction Pinmemberac sakura1:53 7 Jul '06  
    GeneralSlightly Off Topic Pinmember69 Bay6:26 4 Jul '06  
    Generaltooltips Pinmemberramyasangeet21:52 8 Mar '06  
    Generaldinamic creation PinmemberMax Santos14:09 8 Feb '06  
    GeneralButton Not Showing up Pinmembertweetpiyo7:15 6 Feb '06  
    GeneralMinor improvement - transparent background PinmemberHans Dietrich9:11 5 Sep '04  
    GeneralRe: Minor improvement - transparent background PinmemberAnne Jan Beeks3:32 25 Jun '05  
    GeneralRe: Minor improvement - transparent background PinmemberSims0:36 11 Aug '05  
    GeneralRe: Minor improvement - transparent background Pinmembernewofilms15:04 7 Dec '05  
    GeneralButton as Hyperlink in MFC PinmemberSunilJoshi_MCA1:59 24 Mar '04  
    GeneralSomething maybe better! PinmemberTailor21:06 28 Feb '04  
    GeneralProblem compiling example in VC++ 7 PinmemberSick@work2:34 4 Nov '03  
    GeneralRe: Problem compiling example in VC++ 7 PinsussHJ Jo1:57 12 Dec '03  
    GeneralRe: Problem compiling example in VC++ 7 PinmemberJust_a_girl22:58 15 May '04  
    GeneralRe: Problem compiling example in VC++ 7 Pinmemberihawley22:58 19 Jul '04  
    GeneralTrackMouseEvent Pinmembershinay11:57 19 Jul '03  
    GeneralRe: TrackMouseEvent PinsussAnonymous22:04 25 Aug '03  

    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.

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