Creating a Hovering Control

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read