Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CHoverButton - A Simple hoverbutton with One Bitmap and a tooltip

0.00/5 (No votes)
12 Oct 2000 1  
A simple drop-in class that provides a 'hot' look button using the _TrackMouseEvent function

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 your 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 its 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.

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