Creating a Hovering Control

Environment: VC6 SP5, WIN2K SP2

This is a template class for creating hovering controls. It uses the _TrackMouseEvent method to recieve notifications regarding mouse events.

To use it, you need to create a new class deriving from the desired type (CButton, CEdit, and so forth) and add the template code there. You also need to override two pure virtual functions: OnOverEnter() and OnHoverLeave(). Your class recieves notifications via those functions. There is also a function called IsHover(), which can return the hovering state.

In the demo project, I've created two simple classes; one is derived from CButton and the other one is derived from CEdit. They both react to mouse events.

#include "TrackControl.h"
class CHoverButton : public CTrackControl<CButton>
{
public:
  virtual void OnHoverEnter()
  {
    Invalidate();
  }
  virtual void OnHoverLeave()
  {
    Invalidate();
  }
}

Downloads

Download demo project - 24 Kb
Download source - 1 Kb


Comments

  • it's awesome!

    Posted by Legacy on 01/07/2004 12:00am

    Originally posted by: jjm

    simple but works fine!

    Reply
  • _TrackMouseEvent() is not Win95 compliant.

    Posted by Legacy on 04/27/2003 12:00am

    Originally posted by: Mouse

    Controls that use _TrackMouseEvent() fail when run on Windows95. The best way to go about catching a "MouseLeave()" event is to use set a timer on the MouseOver event and use WindowFromPoint() API on the timer fire to check if it is still over the control.

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

Top White Papers and Webcasts

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • On-demand Event Event Date: December 3, 2014 Microsoft SQL Server includes a high availability option called AlwaysOn Availability Groups (AGs). In this session we will see how AGs are implemented using a Windows Server Failover Cluster and SQL Server 2014 with the Pure Storage FlashArray. We will showcase how to use Pure Storage snapshots to seed secondary database copies and then replicate to another location for backup or disaster recovery operations. Windows PowerShell and the Pure Storage PowerShell …

Most Popular Programming Stories

More for Developers

RSS Feeds