Board index » cppbuilder » Is there an onmouseout?

Is there an onmouseout?

I have written a program... and I'm using 5 TImage objects as buttons.
Each have 2 states one where they are normal (the mouse is not over the
image) and one where they are changed (the mouse is over the image). But
how do I detect when the mouse have moved away from the image. I use
OnMouseMove to detect the presens of the mouse over the image.

So I need to find a sort of "onmouseout" how?

Tommy Andersen
to...@vip.{*word*104}city.dk

 

Re:Is there an onmouseout?


Sorry wrote my email wrong it is: tomm...@vip.{*word*104}city.dk

Re:Is there an onmouseout?


On Thu, 19 Jul 2001 01:43:07 +0200, Tommy Andersen <tomm...@vip.{*word*104}city.dk>
wrote:

Quote
>I have written a program... and I'm using 5 TImage objects as buttons.
>Each have 2 states one where they are normal (the mouse is not over the
>image) and one where they are changed (the mouse is over the image). But
>how do I detect when the mouse have moved away from the image. I use
>OnMouseMove to detect the presens of the mouse over the image.

>So I need to find a sort of "onmouseout" how?

>Tommy Andersen
>to...@vip.{*word*104}city.dk

Hi Tommy,

   you have to catch two *undocumented* messages: CM_MOUSEENTER and
CM_MOUSELEAVE. For example, you could try to put the following
declarations in the private section of your form.

class TForm1 : public TForm {
.............
private:        // User declarations
    TWndMethod OldWndProc;
    void __fastcall NewWndProc( TMessage &Message );
............

Then, try to put the following lines in the FormCreate event handler
of the form, in order to capture the form's messages flow.

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    OldWndProc = WindowProc;
    WindowProc = NewWndProc;

Quote
}

Now, define the function member that handles the form's messages.

void __fastcall TForm1::NewWndProc( TMessage &Msg )
{
    OldWndProc( Msg );  // call the main handler
    if ( Msg.Msg == CM_MOUSEENTER ) {
        TControl* const C( reinterpret_cast<TControl* const>( Msg.LParam ) );
        TImage* const I( dynamic_cast<TImage* const>( C ) );
        if ( I ) {
            // The mouse (pointer) enters the image pointed by I
            // put your code here
        }
    }
    else if ( Msg.Msg == CM_MOUSELEAVE ) {
             TControl* const C( reinterpret_cast<TControl* const>( Msg.LParam
) );
             TImage* const I( dynamic_cast<TImage* const>( C ) );
             if ( I ) {
                 // The mouse (pointer) leave the image pointed by I
                 // put your code here
             }
         }

Quote
}

Hope this helps.

Best Regards.

Giuliano

Re:Is there an onmouseout?


Quote
"Tommy Andersen" <tomm...@vip.{*word*104}city.dk> wrote in message

news:3B561F0B.8AE2406@vip.{*word*104}city.dk...

Quote
> I have written a program... and I'm using 5 TImage objects as buttons.
> Each have 2 states one where they are normal (the mouse is not over the
> image) and one where they are changed (the mouse is over the image). But
> how do I detect when the mouse have moved away from the image. I use
> OnMouseMove to detect the presens of the mouse over the image.

I haven't looked at Giuliano's post closely but it will probably suit your
needs.  However, if you would like to create a reusable solution then you
should create a new component; for sake of this post we'll call it
THotImage.  If you are unfamiliar with creating components or packages then
there are a few more steps you will need to go through before writing the
following code, ask for help with this if you require further assistance:

  class PACKAGE THotImage : public TImage
  {
    private:
      TNotifyEvent fOnMouseEnter;
      TNotifyEvent fOnMouseLeave;

    protected:
      void __fastcall CMMouseEnter(TMessage& Message);
      void __fastcall CMMouseLeave(TMessage& Message);

    BEGIN_MESSAGE_MAP
      MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
      MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
    END_MESSAGE_MAP(TImage)

    __published:
      __property TNotifyEvent OnMouseEnter = {
        read = fOnMouseEnter, write = fOnMouseEnter };
      __property TNotifyEvent OnMouseLeave = {
        read = fOnMouseLeave, write = fOnMouseLeave };
  };

  void __fastcall THotImage::CMMouseEnter(TMessage& Message)
  {
    inherited::Dispatch(&Message);
    if (fOnMouseEnter)
      fOnMouseEnter(this);
  }

  void __fastcall THotImage::CMMouseLeave(TMessage& Message)
  {
    inherited::Dispatch(&Message);
    if (fOnMouseLeave)
      fOnMouseLeave(this);
  }

Using this technique your component is now reusable across different forms
of your current application and, more importantly, reusable across different
applications.

HTH,

- Clayton

Other Threads