Calling WindowFromPoint within the MouseMove event of a TWinControl causes a MouseOver event at the point passed to WindowFromPoint. Is this a VCL bug? Anybody know if there is a workaround?

Here’s the demo code:
unit Unit7;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm7 = class(TForm)
Button1: TButton;
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7;
implementation
{$R *.dfm}
procedure TForm7.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
WindowFromPoint(Point(Mouse.CursorPos.X, Mouse.CursorPos.Y - 40));
end;
end.
DFM:
object Form7: TForm7
Left = 0
Top = 0
Caption = 'Form7'
ClientHeight = 40
ClientWidth = 116
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 24
Top = 7
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnMouseMove = Button1MouseMove
end
end
I’m using Delphi XE2 on Windows 7 Pro 64bit. I can also reproduce using Delphi 7.
I tested this with a simplest C++ application and observed the same behavior, this is not a VCL bug (as David mentioned in the comments). It’s not related with mouse movements BTW, anytime you call
WindowFromPointpassing a caption button’s coordinates, the peculiarity occurs. And it occurs only on the windows that belong to the thread that makes the call to the function.So, for a workaround, you can call
WindowFromPointfrom a thread. Simple example below, not really a background thread as the code waits for it to finish:It would make sense to test for the conditions which the bug is displayed (OS, themes..) and make the code conditional to avoid the overhead where unnecessary.