Skip to content

Commit

Permalink
GetOwnerWndForMessageBox: Check root owner window.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanrussell authored Dec 29, 2024
1 parent 4b9b957 commit dacb18b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Projects/Src/Shared.CommonFunc.Vcl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,24 @@ function GetOwnerWndForMessageBox: HWND;
if Result = 0 then { shouldn't be possible, but they have this check }
Result := Application.Handle;

{ Now our override }
if ((Result = Application.Handle) and IsIconic(Result)) or
(GetWindowLong(Result, GWL_STYLE) and WS_VISIBLE = 0) or
(GetWindowLong(Result, GWL_EXSTYLE) and WS_EX_TOOLWINDOW <> 0) then
{ Now our overrides }
if (Result = Application.Handle) and IsIconic(Result) then
Exit(0);

{ Find the "root owner" window, which is what appears in the taskbar.
We avoid GetAncestor(..., GA_ROOTOWNER) because it's broken in the same
way as GetParent(): it stops if it reaches a top-level window that doesn't
have the WS_POPUP style (i.e., a WS_OVERLAPPED window). }
var RootWnd := Result;
while True do begin
var ParentWnd := HWND(GetWindowLongPtr(RootWnd, GWLP_HWNDPARENT));
if ParentWnd = 0 then
Break;
RootWnd := ParentWnd;
end;

if (GetWindowLong(RootWnd, GWL_STYLE) and WS_VISIBLE = 0) or
(GetWindowLong(RootWnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW <> 0) then
Result := 0;
end;

Expand Down

0 comments on commit dacb18b

Please sign in to comment.