My spy gave me wrong information, and because of that I gave you incorrect information, sorry!
Here is the code for getting the proper window at the specified screen point:
- Code: Select all
function WindowAtPt(const Pt: TPoint): HWND;
type
TChildInfo = record
ChildWnd: HWND;
ChildRect: TRect;
end;
var
WndPoint: HWND;
WndChild: HWND;
NextChildWnd: HWND;
Rect: TRect;
CPt: TPoint;
ChildList: array of TChildInfo;
MinNbrPixel: Integer;
NbrPixel: Integer;
I: Integer;
begin
WndPoint := WindowFromPoint(Pt);
CPt := Pt;
ScreenToClient(WndPoint, CPt);
WndChild := ChildWindowFromPointEx(WndPoint, CPt, CWP_ALL);
if WndChild = 0 then
Result := WndPoint
else if not IsChild(GetParent(WndChild), WndChild) then
Result := WndChild
else
begin
NextChildWnd := GetWindow(WndChild, GW_HWNDFIRST);
while NextChildWnd <> 0 do
begin
GetWindowRect(NextChildWnd, Rect);
if PtInRect(Rect, Pt) then
begin
SetLength(ChildList, Length(ChildList) + 1);
with ChildList[Length(ChildList) - 1] do
begin
ChildWnd := NextChildWnd;
ChildRect := Rect;
end;
end;
NextChildWnd := GetWindow(NextChildWnd, GW_HWNDNEXT);
end;
if Length(ChildList) > 0 then
begin
WndChild := ChildList[0].ChildWnd;
MinNbrPixel := GetSystemMetrics(SM_CXFULLSCREEN) * GetSystemMetrics(SM_CYFULLSCREEN);
for I := 0 to Length(ChildList) - 1 do
begin
with ChildList[I].ChildRect do
NbrPixel := (Right - Left) * (Bottom - Top);
if NbrPixel < MinNbrPixel then
begin
MinNbrPixel := NbrPixel;
WndChild := ChildList[I].ChildWnd;
end;
end;
SetLength(ChildList, 0);
Result := WndChild;
end
else
Result := 0;
end;
end;
By the way, the code is from the application you've attached in your last post, which I translated it to Delphi.
Greetings