Mouse position to achieve real-time display through WinAPI GetCursorPos
Sometimes we need to crawl out of the mouse's location in real time, it can be achieved as follows.
Add a Timer control, the execution interval to 100ms, the control is double enter the following code:
1 var 2 P: TPoint; 3 begin 4 GetCursorPos(P); 5 RzLabel_Point.Caption := Format('(%d,%d)', [P.X,P.Y]); 6 end;
Enter the following code in the form Show event, the mouse to adjust the display style:
1 Screen.Cursor := crHandPoint;
final effect:
Unit code as follows:
1 unit U_Operation; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, ExtCtrls, RzPanel, StdCtrls, RzLabel; 8 9 type 10 TFrm_Operation = class(TForm) 11 RzGroupBox1: TRzGroupBox; 12 RzGroupBox2: TRzGroupBox; 13 Timer_Display: TTimer; 14 RzLabel1: TRzLabel; 15 RzLabel_Point: TRzLabel; 16 procedure Timer_DisplayTimer(Sender: TObject); 17 procedure FormCreate(Sender: TObject); 18 private 19 { Private declarations } 20 public 21 { Public declarations } 22 end; 23 24 var 25 Frm_Operation: TFrm_Operation; 26 27 implementation 28 29 {$R *.dfm} 30 31 procedure TFrm_Operation.Timer_DisplayTimer(Sender: TObject); 32 var 33 P: TPoint; 34 begin 35 GetCursorPos(P); 36 RzLabel_Point.Caption := Format('(%d,%d)', [P.X,P.Y]); 37 end; 38 39 procedure TFrm_Operation.FormCreate(Sender: TObject); 40 begin 41 Screen.Cursor := crHandPoint; 42 end; 43 44 end.