I have found a very strange Delphi IDE behavior related to cursor position.
Create a sample project:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TForm2 = class(TForm)
ListBox1: TListBox;
Panel1: TPanel;
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
FStartLog : boolean;
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FStartLog := True;
end;
procedure TForm2.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if FStartLog then ListBox1.Items.Add(Format('X = %d; Y = %d', [X, Y]))
end;
procedure TForm2.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FStartLog := False;
end;
end.
We have a simple Form with a ListBox for logging, and a Panel. When we click a mouse button on the Panel, we receive mouse messages until the button is released.
The strange things occur when the mouse leaves the Panel Form. When we run the application with the Delphi IDE in the background and click the right mouse button and move right, we see the following:
X = 218; Y = 228
X = 237; Y = 228
X = 257; Y = 227
X = 313; Y = 226
X = 315; Y = 226
X = 333; Y = 225
X = 334; Y = 225
X = 353; Y = 224
X = 379; Y = 224
X = 380; Y = 224
X = 381; Y = 224
X = -288; Y = 61
X = -288; Y = 61
X = -287; Y = 61
The X and Y coordinates are different when we go out of the Form.
OK, maybe it is related to conversation between screen and client coordinates. So, minimize the IDE and we see the desktop in the background and do the same thing.
X = 222; Y = 144
X = 229; Y = 144
X = 230; Y = 144
X = 231; Y = 144
X = 232; Y = 144
X = 233; Y = 144
X = 234; Y = 144
X = 273; Y = 144
X = 314; Y = 147
X = 317; Y = 147
X = 345; Y = 148
X = 347; Y = 148
X = 373; Y = 148
X = 375; Y = 148
X = 377; Y = 149
We see that we get the correct coordinates.
Note in all cases that the application is running under the Delphi IDE, but run outside Delphi changes nothing. This behavior occurs when the application window shows over the Delphi IDE. So, I think this is a bug in some mouse hooks created by the Delphi IDE.
I am checking this issue with XE7 and 10.4.
Am I correct?
Some addition, after investigation I see that bug related to High Dpi feature, if top window correctly works with high Dpi and bottom window have a display scaling on high DPI. So, the WM_NCHITTEST first go to bottom window (we can cursor over it) and they convert coordinates according scaling and after a window that capture mouse received a message, but the coordinates remains scaling. Tested on Windows 7.