Board index » cppbuilder » Mouse Hover or Mouse Over?

Mouse Hover or Mouse Over?

I'm looking to capture the mouse being positioned over a certain component
in an application so that I can change the cursor of the mouse to let the
user know that the component the mouse is over is "clickable", however I
only find events on a TLabel component that can respond to OnClick,
OnDblClick, OnDragDrop, etc.  I don't find something like a OnMouseOver.
How does one accomplish this?

Thanks,
Todd

 

Re:Mouse Hover or Mouse Over?


I'm using BCB 3.0 build 3.7 if that is relevant.

Todd

Re:Mouse Hover or Mouse Over?


"Todd Hale" <katysports...@houston.rr.com> schreef in bericht
news:3ea1879a$1@newsgroups.borland.com...

Quote
> I'm looking to capture the mouse being positioned over a certain component
> in an application so that I can change the cursor of the mouse to let the
> user know that the component the mouse is over is "clickable", however I
> only find events on a TLabel component that can respond to OnClick,
> OnDblClick, OnDragDrop, etc.  I don't find something like a OnMouseOver.
> How does one accomplish this?

Every control has a Cursor property. Setting this property is all you have
to do.

Peter

Re:Mouse Hover or Mouse Over?


Quote
"Todd Hale" <katysports...@houston.rr.com> wrote in message

news:3ea1879a$1@newsgroups.borland.com...

Quote
> I'm looking to capture the mouse being positioned over a certain component
> in an application so that I can change the cursor of the mouse to let the
> user know that the component the mouse is over is "clickable", however I
> only find events on a TLabel component that can respond to OnClick,
> OnDblClick, OnDragDrop, etc.  I don't find something like a OnMouseOver.
> How does one accomplish this?

> Thanks,
> Todd

This assumes your TLabel is named Label1. You can override it's wndproc

Add this to your forms header file

//------------------------------------------------------
protected:
        TWndMethod OldLabel1WndProc;
        void __fastcall NewLabel1WndProc(TMessage &Msg);
//------------------------------------------------------

Put this in your forms construtor

//------------------------------------------------------
   OldLabel1WndProc = Label1->WindowProc;
   Label1->WindowProc = NewLabel1WndProc;
//-------------------------------------------------------

Then add this function

//------------------------------------------------------
void __fastcall TForm1::NewLabel1WndProc(TMessage &Msg)
{
   OldLabel1WndProc(Msg);

   if(Msg.Msg == CM_MOUSEENTER)
   {
     Cursor = crHandPoint;
   }
   if(Msg.Msg == CM_MOUSELEAVE)
   {
     Cursor = crDefault;
   }

Quote
}

//-------------------------------------------------------

Re:Mouse Hover or Mouse Over?


Ok, Peter, I found the Cursor property, and that works exactly as I need it,
thanks for the help!

Todd

Re:Mouse Hover or Mouse Over?


Quote
"Todd Hale" <katysports...@houston.rr.com> wrote in message

news:3ea1879a$1@newsgroups.borland.com...

Quote
> I'm looking to capture the mouse being positioned over
> a certain component in an application so that I can change
> the cursor of the mouse to let the user know that the
> component the mouse is over is "clickable"

You don't really need to handle that manually.  Just set the component's
Cursor property at design-time to the desired cursor, then the VCL will
handle all of that automatically for you at runtime.  That is the whole
point of the Cursor property - to display a particular cursor when the mouse
is over the component.

Quote
> however I only find events on a TLabel component that
> can respond to OnClick, OnDblClick, OnDragDrop, etc.
> I don't find something like a OnMouseOver. How does
> one accomplish this?

There are no exposed events for that.  If you must handle it manually, then
you need to intercept the CM_MOUSEENTER message directly, by subclassing the
component.  If you don't know how to subclass, then have a look at this
article:

    Sublcass a windows control
    http://www.bcbdev.com/faqs/faq76.htm

Gambit

Other Threads