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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • QA teams don't have time to test everything yet they can't afford to ship buggy code. Learn how Coverity can help organizations shrink their testing cycles and reduce regression risk by focusing their manual and automated testing based on the impact of change.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds