Lazarus

Programming => LCL => Topic started by: CM630 on August 05, 2021, 09:52:07 am

Title: Detect that mouse cursor is over the title bar
Post by: CM630 on August 05, 2021, 09:52:07 am
How am I to detect that the mouse cursor is over the title bar of the form?
The OnMouseMove event is not triggered when the mouse is over the title bar.
So I thought I could detect OnMouseMove for the entire OS, but I have found a Windows-only solution.
In the worst case, I can place a timer that will check the position of the mouse let say every 150 ms, but probably that is not the best way.
Title: Re: Detect that mouse cursor is over the title bar
Post by: jamie on August 05, 2021, 01:18:40 pm
Process the lm_nchittest message.
Title: Re: Detect that mouse cursor is over the title bar
Post by: jamie on August 06, 2021, 12:24:41 am
How am I to detect that the mouse cursor is over the title bar of the form?
The OnMouseMove event is not triggered when the mouse is over the title bar.
So I thought I could detect OnMouseMove for the entire OS, but I have found a Windows-only solution.
In the worst case, I can place a timer that will check the position of the mouse let say every 150 ms, but probably that is not the best way.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,lmessages,lclintf;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.   private
  13.  
  14.   public
  15.     Procedure WMMouseMove(Var msg:TLMessage) message LM_MouseMove;
  16.     procedure WMNCMouseMove(var msg:TLmessage) message LM_NCMouseMove;
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25. procedure Tform1.WMNCMouseMove(var msg:TLmessage);
  26. Begin
  27.   inherited;
  28.   caption := SmallInt(LO(DWORD(Msg.lParam))).Tostring+','+SmallInt(HI(DWORD(Msg.Lparam))).Tostring;
  29. End;
  30. Procedure TForm1.WMMouseMove(Var msg:TLmessage);
  31. Var
  32.   X,Y:SmallInt;
  33.   P:TPoint;
  34.  Begin
  35.    inherited;
  36.    X := SmallInt(Lo(DWord(Msg.Lparam)));
  37.    Y := SmallInt(Hi(DWOrd(msg.Lparam)));
  38.    P := ClientToScreen(Point(X,Y));
  39.    caption := P.X.Tostring+','+P.Y.Tostring;
  40.  end;
  41.  
  42. end.
  43.  
  44.  

 That will respond to caption or client and it seems to be cross platform because the Lmessages and lclintf is all that is needed.
Title: Re: Detect that mouse cursor is over the title bar
Post by: CM630 on August 23, 2021, 02:02:08 pm
Thanks.
1. It did not compile at first until I added types in the uses section.

2. Procedure Tform1.WMNCMouseMove(var msg:TLmessage); fires when the mouse cursor is over the title bar or over the borders of the form.
3. Procedure TForm1.WMMouseMove(Var msg:TLmessage); fires when I am somewhere else on the form.

So it is still not exactly what I need. I will read some more...
TinyPortal © 2005-2018