procedure CloseAllPopupWindows(const AHandle: THandle);
var
h, h2: THandle;
pid, pid2: DWord;
r: TRect;
begin
GetWindowThreadProcessId(AHandle, @pid);
h := GetWindow(AHandle, GW_HWNDFIRST);
while h <> 0 do begin
h2 := h;
h := GetWindow(h, GW_HWNDNEXT);
if (h2 <> AHandle) and IsWindowVisible(h2) and GetWindowRect(h2, r) and (r.Right > r.Left) then begin
GetWindowThreadProcessId(h2, @pid2);
if pid = pid2 then begin
SendMessage(h2, WM_CLOSE, 0, 0);
end;
end;
end;
SetForegroundWindow(AHandle);
end;
//delphi/6735