CHoverButton - Nice Hover Button with One Bitmap and Tooltip. | CodeGuru

CHoverButton – Nice Hover Button with One Bitmap and Tooltip.

Looking around for some nice bitmap hoverbuttons, I just couldn’t find what I was looking for. In this case there are a couple of things you can do: Leave it. Buy it. Steal it. Get it for free. Start crying Do it yourself (and possibly share it.) I’ll share! I found another hoverbutton class that […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 9, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Looking around for some nice bitmap hoverbuttons, 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 gives earlier or later some problems. I can’t remember why, but it
did to me. So I thought why do it so diffifcult? MS has a nice API to handle hoverstates:
_TrackMouseEvent().

So here it, the class. After a long thought i decided to call it: ‘CHoverButton’.
I used some classes and information found elsewhere on
CodeGuru (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 bimaps here.
  6. In the OnInitDialog() load the bitmap with mybutton.LoadBitmap(IDC_MYBUTTON);
  7. Set a tooltip with mybutton.SetToolTipText();
  8. Compile and watch.

Have fun!

Downloads

Download demo project with source – 34 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.