Hover buttons


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

, and is a varation on Guy Gascoigne's CTrackLookButton class.

This CHoverButton class is best used in a bank of radio buttons, and behaves like scripted mouse sensitive "pop-up" buttons on web pages.

This article describes how to use this class as a bank of 4 radio buttons.

  1. Add 4 owner drawn buttons to a dialog, labelling each with text labels (if required).
  2. Use classwizard to add CButton member variables.
  3. In your dialog's header file, change the class type from CButton to CHoverButton.
  4. Add the HoverButton.cpp and HoverButton.h source files to your project.
  5. #include "HoverButton.h" in the dialog's header file.
  6. Design: up, down, focussed and disabled bitmaps for each button, or one set for all buttons (see my example).
  7. Use class wizard to add OnInitDialog() to your dialog's source file.
  8. In OnInitDialog(), for each button, call LoadBitmaps() passing the bitmap ID's required for each button.
  9. Add handler functions for BN_CLICKED for each button and add your processing in these functions.
  10. Add a function to your dialog class to reset all button highlighting to OFF, then set the button which has just been pressed to ON.
  11. Call this function after LoadBitmaps(), in your OnInitDialog() function.
  12. Call this function in each of the BN_CLICKED button handler functions.



Source for updated Hoverbutton with bug fixes
  1. Greyed bitmap displayed properly
  2. Accelerator key added to project for fast exit


Compiled release of hover button project

hover_group_src.zip(thanks to Jack van Dijk)

Source if project to demonstrate CObjectArray with Hoverbuttons


Compiled executable of hover group project

Posted 7 November 1998.
Last Updated 27 March, 1999


  • I repaired Hamid Yaseen's point

    Posted by Legacy on 05/07/2003 07:00am

    Originally posted by: soy

    I've tried to repair the point..
    I used CHoverButton very useful..

    to repaire the point..
    in 'hovbuttDlg.cpp'
    in this class..
    int CHovbuttDlg::RefreshButtons(int nSelected /*=0*/ )

    add "Invalidate();"
    before "return nSelected;" statement

    It's very simple but I tried all day..^^
    Have nice day~

  • Background image drawing over buttons

    Posted by Legacy on 04/10/2003 07:00am

    Originally posted by: Jeff

    Hello, I have a dialog with a background picture. The hover buttons won't show up until I hover the mouse over top of them. How can I get them to show up right away?

    Note that with normal buttons I just set the tab order so that the buttons are last, but the hover buttons don't work like this.


  • Hover tooltips in an ActiveX Control

    Posted by Legacy on 06/17/2002 07:00am

    Originally posted by: Henry Park

    I'm having a bit of trouble getting the tooltip text to appear. I'm building an ActiveX control that utilizes "hover" and "tooltips". The hover aspect works fine, but, the tooltip text does not appear. If anyone is interested in helping me, I'll send some code.


  • Another way (probably good VB and C++)

    Posted by Legacy on 10/09/2001 07:00am

    Originally posted by: Isaac Eckert

    Try creating a Bitmap Button were the Disabled state is when most is not over the button and the Enabled state is when it is over the button. After creating the button, position it where you wish and disable it. When the button is disabled all OnMouseMove messages go to the parent window instead of the button. You can then test the position of the mouse in the window to see if it is over the button. Then enable the button to be clicked. When the mouse moves out of the area it will receive the OnMouseMove message and you can disable the button. It is easier to test for rectangler regions but with a little math any region can be tested for. Use the SetWindowRgn fuction in vc++ to shape the button. The only bug is that if you move into another window without sending a OnMouseMove message, the button stays enabled until the mouse is moved back.

  • how in VB?

    Posted by Legacy on 09/09/2001 07:00am

    Originally posted by: Ranjanie

    Please also intimate me that how to create hoverbutton in Visual Basic 6.0.

  • One Main Error

    Posted by Legacy on 05/22/2001 07:00am

    Originally posted by: Hamid Yaseen

    Hello Dear
    Your class has a main error whose senario is as
    At a time there is only one button is on and all other buttons are off. Take mouse over any off state button with left button Down and then leave the left button.It will calls left button up. In this way the two radio buttons become on. Which is wrong.
    Hamid Yaseen

  • HoverButton - TransparentBlt

    Posted by Legacy on 01/25/2001 08:00am

    Originally posted by: sten struikenkamp

    Hi Will,

    I like your radio Hoverbutton class.
    It works fine !
    Thanks !

    I only noticed that setting the background color of the bitmaps
    to (192,192,192) works fine in W98 but not in W2000.
    The 'COLOR_BTNFACE' is diferent !
    W2000 -> (212,208,200)
    The difference is not much, but you can still see it on your dialog.

    I replaced your 'BitBlt' with the code below for 'transparent bit blitting'.
    'TransparentBlt' however, only works for W98 and W2000.
    You can use any transparent color for your bitmap background, but i suggest
    you use (200,200,200) so that the code will also work for W95/NT4.0 (?).
    (I only have W98/W2000, so I could not test it for W95/NT4.0).
    The code below uses pixel(0,0) to get the transparent color.
    The transparent color must not exist in your button image !
    For example, if you use 'magenta' for your background, magenta must not exist
    in the button image. Otherwise the (lightgray) underground will shine through.

    CDC dcTemp;
    CBitmap bmpTemp, *bmpOldTemp;
    bmpOldTemp = dcTemp.SelectObject(&bmpTemp);
    // (212,208,200) Win2000
    // (192,192,192) Win98
    dcTemp.BitBlt(0, 0, rc.Width(), rc.Height(), &memDC,
    0, 0, SRCCOPY);
    COLORREF clrTransparent = dcTemp.GetPixel(0,0);

    // TransparentBlt only for Win2000 and Win98
    if( !TransparentBlt(pDC->GetSafeHdc(),
    clrTransparent) )
    if(!pDC->BitBlt(0, 0, rc.Width(), rc.Height(), &memDC,
    0, 0, SRCCOPY))

    note: use msimg32.dll/msimg32.lib

    Thanks again !
    Hope this helps...

    Sten Struikenkamp
    The Netherlands

    the statement '!TransparentBlt' (note the .not.) will probably not work
    in W95/NT4.0. This was done to give 'BitBlt' a chance to do the work.
    But there must be a way to figure out if the function is available in W95/NT4.0.
    I have seen such a piece of code somewhere, but i cannot remember...

  • add a tip to a button

    Posted by Legacy on 01/19/2001 08:00am

    Originally posted by: miki

    what if i have to add a tip to my button on the head of the mouse pointer ??
    uptill now i hav seen only tooltips but not a button tip help anywhere ??
    should i add a ? button on the sys menu bar and then create a .hlp file for it ??
    any other way of doin the same thing ??

  • Non-Radio Button

    Posted by Legacy on 09/10/2000 07:00am

    Originally posted by: Dark Mage

    I managed to change a few things to get the code changned 
    for a regular Button (not radio). However, it doesn't
    want respond to the first CLICK of the button for some reason? Here's the main area I changed:

    void CHoverButton::OnLButtonUp(UINT nFlags, CPoint point)
    CBitmapButton::OnLButtonUp(nFlags, point);

    void CHoverButton::OnLButtonDown(UINT nFlags, CPoint point)
    SetButtonState(BUTTON_ON); //Highlight button
    CBitmapButton::OnLButtonDown(nFlags, point);

    Any idea why the button doesn't respond to the first
    click? And why it would respond perfectly every time there


  • But if i have to insert resource bitmap not from any file ?

    Posted by Legacy on 04/23/2000 07:00am

    Originally posted by: abhishek

    if i have to insert bitmap from my resource collection using its Id...what to do then ?


  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date