function GetApplicationWindow(ParentWnd: HWND; Pt: TPoint): HWND;
var
R: TRect;
begin
Result := GetWindow(ParentWnd, GW_CHILD); // 取得第一個子視窗
while Result <> 0 do
begin
GetWindowRect(Result, R); // 取得視窗矩形區域
if IsWindowVisible(Result) and PtInRect(R, Pt) then
begin
if Result = frmWndExplorer.Form.Handle then // 忽略程式的 Main Form
begin
Result := 0;
Exit;
end;
Exit;
end;
Result := GetWindow(Result, GW_HWNDNEXT); // 取得下一個 siblings 視窗
end;
Result := ParentWnd; // 找不到, 它就是我們要找的
end;