Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6216607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:16:40+00:00 2026-05-24T07:16:40+00:00

I want to write a little component which shows me on which control mouse

  • 0

I want to write a little component which shows me on which control mouse is currently over.
When it spot the choosen control it should fire the messaage (for example).

But I don’t know what should I do to form to get the position of the mouse all the time.
This is what I’ve got:

  TMouseOverControl = class(TComponent)
  private
    fActive: Boolean;
    fControl: TWinControl;
  public
    constructor Create(AOwner: TComponent); override;
    procedure Loaded; override;
    procedure SpotIt;
  published
    property Active: Boolean read fActive write fActive;
    property Control: TWinControl read fControl write fControl; // when mouse is over this control show me the message
  end;

constructor TMouseOverControl.Create(AOwner: TComponent);
begin
  // nothing interesting here
  // don't have control property here - so overrided the loaded method
  inherited;
end;

procedure TMouseOverControl.Loaded;
begin
  inherited;

  //  TForm(Owner).Mo.... := SpotIt.... 
  //  what should i do to make it work?
 end;

 procedure TMouseOverControl.SpotIt;
 begin
// IsMouseOverControl is easy to implement
// http://delphi.about.com/od/delphitips2010/qt/is-some-delphi-tcontrol-under-the-mouse.htm
       if IsMouseOverControl(Control) then 
         ShowMessage('Yep, U got it!');
     end;

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:16:42+00:00Added an answer on May 24, 2026 at 7:16 am

    Well you only need to check/update when the mouse moves. So you could track WM_MOUSEMOVE messages by using TApplicationEvents.

    // Edit: these variables are intended to be private fields of the component class
    var
      FAppEvents: TApplicationEvents;
      FFoundControl: Boolean;
      FCurrentControl: TWinControl;
    
    procedure TMyComponent.HandleAppMessage(var Msg: tagMSG; var Handled: Boolean);
    var
      Control: TWinControl;
    begin
      if (Msg.message = WM_MOUSEMOVE) and not FFoundControl then
      begin
        Control:= FindControl(Msg.hwnd);
        if Assigned(Control) then
        begin
          FCurrentControl:= Control;
          FFoundControl:= True;
        end;
      end else
      if (Msg.message = WM_MOUSELEAVE) then
        FFoundControl:= False;
    end;
    
    procedure TMyComponent.FormCreate(Sender: TObject);
    begin
      FAppEvents:= TApplicationEvents.Create(nil);
      FAppEvents.OnMessage:= HandleAppMessage;
    end;
    

    This could certainly be optimized, e.g. by also checking for WM_MOUSELEAVE so you don’t have to FindControl on every mouse move. This solution works for TWinControls and descendants.

    Edit: Made use of WM_MOUSELEAVE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a little app for myself which notifies me if there
I want to write a little helper method which returns the base URL of
I want to write a little DBQuery function in perl so I can have
I have SBCL running on a Ubuntu machine. I want to write a little
Hello I want write my own desktop sharing application in Java. The application should
I want to write a little program in C to extract the PE (Entry
I want to write a little program that transforms my TeX files into HTML.
This is for a little pet project of mine. I want to write a
I want to write a little function to generate samples from appropriate distributions, something
I want to write a little application for myself to learn C# and WPF.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.