CHoverButton - Nice Hover Button with One Bitmap and Tooltip.
Posted
by Niek Albers
on October 9th, 2000
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 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?
- In you resource editor create a button and set the 'owner draw' property.
- Use classwizard to create a CButton object in your dialog.
- Include the "hoverbutton.h" file in your dialog class file.
- Rename the 'CButton' object type to 'CHoverButton'.
- 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. - In the OnInitDialog() load the bitmap with mybutton.LoadBitmap(IDC_MYBUTTON);
- Set a tooltip with mybutton.SetToolTipText();
- Compile and watch.
Have fun!

Comments
When mouse cursor's shape is changed suddenly..in WinXP
Posted by demeter2 on 09/15/2005 10:32pmI think that it happens in WindowXP only because many CHoverButtons in Windows 2K there were no problem. When mouse over the button my cursor's shape is changed to the Information graphic suddenly. The solution is like below. In your CHoverButton::CHoverButton() function add next initialization code. m_CursorHand = NULL; It will work well. And thanks to the author for great work.
ReplyDynamic button
Posted by Legacy on 06/19/2003 12:00amOriginally posted by: james
How do you create this button dynamically and still have the tooltip work?
Reply
ToolTip does NOT appear with MODELESS dialog
Posted by Legacy on 06/11/2003 12:00amOriginally posted by: Don
Using a modeless dialog, the tool tip does not appear to work because the PreTranslateMessage() does not get called.
How can I get around this???
Thanks in advance,
ReplyDon
Fix LoadBitmap() function for using on child dialog
Posted by Legacy on 10/09/2002 12:00amOriginally posted by: Kanghee Im
ReplyA FIX for the blinking when entering and leaving the button
Posted by Legacy on 10/03/2002 12:00amOriginally posted by: Jaisor
First of all, thanks for the excelent code, saved me days of looking up.
I noticed an annoying bliking when the mouse enters and leaves the button, it is caused by the erasing on every Invalidate() so I used Invalidate(FALSE) which prevents erasing and it worked like a charm.
ReplyBug Fix - Ignore double-click
Posted by Legacy on 08/13/2002 12:00amOriginally posted by: Cho Yong Kil
ReplyYeah !
Posted by Legacy on 07/31/2002 12:00amOriginally posted by: TheFlashback
You have no idea how many troubles Set/Release Capture() brings. This code is neat and awesome. _TrackMouseEvent is just freaking splendid!
ReplyActiveX Control with "hover" button - help with tooltip test not being displayed...
Posted by Legacy on 06/17/2002 12:00amOriginally posted by: Henry Park
ReplyIts a great help!
Posted by Legacy on 06/12/2002 12:00amOriginally posted by: Anand Raval
Hi Niek,
Thanks a lot. You've saved my lots of research time! It is really great help to me.
Thanks again,
ReplyAnand
Thank you.
Posted by Legacy on 03/03/2002 12:00amOriginally posted by: mutter21
Good!! It's very simple code!!
Thank you.. *^^*
Reply
Loading, Please Wait ...