65.9K
CodeProject is changing. Read more.
Home

Hovering Control Template

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.89/5 (9 votes)

Oct 27, 2002

viewsIcon

42534

downloadIcon

1425

A template class to add hovering support to any control.

Sample Image - trackcontrol.jpg

Introduction

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

Using the code

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

In the demo project, I've created 2 simple classes: One derived from CButton and the other one 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();
    }
}

History

  • 10/27/2002 - First release