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

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds