I tested this with the simplest C ++ application and observed the same behavior, this is not a VCL error (as David mentioned in the comments). This is not related to the BTW mouse movement, any time you call WindowFromPoint , passing the coordinates of the title button, a special feature arises. And this only happens in windows belonging to the thread that calls the function call.
So, for a workaround, you can call WindowFromPoint from the stream. The simple example below is not really a background thread, since the code is waiting for it to complete:
type TGetWndThread = class(TThread) private FPoint: TPoint; protected procedure Execute; override; constructor Create(AOwner: TComponent; Point: TPoint); end; constructor TGetWndThread.Create(AOwner: TComponent; Point: TPoint); begin FPoint := Point; inherited Create; end; procedure TGetWndThread.Execute; begin ReturnValue := WindowFromPoint(FPoint); end; .. var Wnd: HWND; Thr: TGetWndThread; begin Thr := TGetWndThread.Create(nil, Point(Mouse.CursorPos.X, Mouse.CursorPos.Y - 40)); Wnd := Thr.WaitFor; Thr.Free; .. // use Wnd
It would be advisable to test the conditions that display the error (OS, themes ..), and make the code conditional in order to avoid unnecessary costs if this is not necessary.
source share