From 5445a84dc4061a656cef84b93e58f8ff7f724cce Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 21 Mar 2011 07:53:51 +0000 Subject: [PATCH] win32: hide/restore popup windows on application.minimize/restore (issue #0016577) git-svn-id: trunk@29955 - --- lcl/interfaces/win32/win32callback.inc | 2 + lcl/interfaces/win32/win32proc.pp | 53 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/lcl/interfaces/win32/win32callback.inc b/lcl/interfaces/win32/win32callback.inc index dc759fea95..329150e9e8 100644 --- a/lcl/interfaces/win32/win32callback.inc +++ b/lcl/interfaces/win32/win32callback.inc @@ -803,6 +803,7 @@ var if (Window = Win32WidgetSet.AppHandle) and not Application.MainFormOnTaskBar then begin + HidePopups(Win32WidgetSet.AppHandle); if Assigned(Application.MainForm) then begin Windows.SetWindowPos(Window, HWND_TOP, @@ -838,6 +839,7 @@ var begin if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainFormHandle, SW_SHOWNA); + RestorePopups; end; Application.IntfAppRestore; end diff --git a/lcl/interfaces/win32/win32proc.pp b/lcl/interfaces/win32/win32proc.pp index 7bca1996bf..18ab820e74 100644 --- a/lcl/interfaces/win32/win32proc.pp +++ b/lcl/interfaces/win32/win32proc.pp @@ -104,6 +104,8 @@ function GetWin32WindowInfo(Window: HWND): PWin32WindowInfo; procedure RemoveStayOnTopFlags(Window: HWND; ASystemTopAlso: Boolean = False); procedure RestoreStayOnTopFlags(Window: HWND); +procedure HidePopups(AppHandle: HWND); +procedure RestorePopups; procedure AddToChangedMenus(Window: HWnd); procedure RedrawMenus; @@ -136,6 +138,12 @@ type SystemTopAlso: Boolean; StayOnTopList: TList; end; + + PPopupOwnersWindowInfo = ^TPopupOwnersWindowInfo; + TPopupOwnersWindowInfo = record + AppHandle: HWND; + OwnersList: TList; + end; TWindowsVersion = ( wvUnknown, @@ -176,6 +184,7 @@ uses var InRemoveStayOnTopFlags: Integer = 0; + PopupOwnersList: TList = nil; {------------------------------------------------------------------------------ function: WM_To_String Params: WM_Message - a WinDows message @@ -1021,6 +1030,49 @@ begin // WriteLn('RestoreStayOnTopFlags 2'); end; +function EnumHidePopups(Handle: HWND; Param: LPARAM): WINBOOL; stdcall; +var + Owner: HWND; +begin + Owner := GetWindow(Handle, GW_OWNER); + if (Owner <> 0) and (Owner <> PPopupOwnersWindowInfo(Param)^.AppHandle) then + PPopupOwnersWindowInfo(Param)^.OwnersList.Add(Pointer(Owner)); + Result := True; +end; + +procedure HidePopups(AppHandle: HWND); +var + i: Integer; + Info: PPopupOwnersWindowInfo; +begin + if not Assigned(PopupOwnersList) then + begin + PopupOwnersList := TList.Create; + New(Info); + try + Info^.AppHandle := AppHandle; + Info^.OwnersList := PopupOwnersList; + EnumThreadWindows(GetWindowThreadProcessId(Application.MainFormHandle, nil), + @EnumHidePopups, LPARAM(Info)); + for i := 0 to PopupOwnersList.Count - 1 do + ShowOwnedPopups(HWND(PopupOwnersList[i]), False); + finally + Dispose(Info); + end; + end; +end; + +procedure RestorePopups; +var + i: Integer; +begin + if Assigned(PopupOwnersList) then + begin + for i := 0 to PopupOwnersList.Count - 1 do + ShowOwnedPopups(HWND(PopupOwnersList[i]), True); + FreeAndNil(PopupOwnersList); + end; +end; {------------------------------------------------------------------------------- procedure AddToChangedMenus(Window: HWnd); @@ -1713,5 +1765,6 @@ finalization Windows.GlobalDeleteAtom(WindowInfoAtom); WindowInfoAtom := 0; ChangedMenus.Free; + FreeAndNil(PopupOwnersList); end.