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

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • In this webinar, IDC featured speaker Steve Conway, Vice President of High Performance Computing, will present an update on the global x86 HPC cluster market. The presentation will include IDC's five-year forecast for the medium- to large-scale technical computing and data analysis emerging markets by systems, processors and application middleware. Cray's featured speaker, John Lee, Vice President of Cray Cluster Advanced Technology Systems, will present the new Cray® CS400™ cluster series based on …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds