BSOne.SFC/Tocsg.Module/FindWindow/ThdCloseSidebar.pas

178 lines
4.1 KiB
Plaintext

{*******************************************************}
{ }
{ ThdCloseSidebar }
{ }
{ Copyright (C) 2024 kku }
{ }
{*******************************************************}
unit ThdCloseSidebar;
interface
uses
Tocsg.Thread, System.SysUtils, Winapi.Windows, DAngle, Winapi.Messages;
type
TThdCloseSidebar = class(TTgThread)
protected
DlgAngle_: TDlgAngle;
procedure Execute; override;
public
Constructor Create(aDlgAngle: TDlgAngle);
end;
implementation
uses
Tocsg.Process, Tocsg.WndUtil, Tocsg.Safe, System.Generics.Collections;
{ TThdCloseSidebar }
Constructor TThdCloseSidebar.Create(aDlgAngle: TDlgAngle);
begin
Inherited Create;
DlgAngle_ := aDlgAngle;
end;
procedure TThdCloseSidebar.Execute;
var
h, hOld: HWND;
// dwPid: DWORD;
sPName, sCap: String;
MainRect, ChildRect: TRect;
i: Integer;
llStyle: LONGLONG;
ChildList: TList<HWND>;
procedure FindChildWnd(hSrc: HWND);
var
hC: HWND;
sClassName: String;
begin
llStyle := GetWindowStyle(hSrc);
if ((llStyle and WS_POPUP) <> 0) and (CompareText(GetWndClassName(hSrc), 'Chrome_WidgetWin_1') = 0) then
begin
// ¿þÀÏ À§Á¬ »çÀ̵å¹Ù Á¦°Å 25_0224 13:50:15 kku
PostMessage(hSrc, WM_CLOSE, 0, 0);
exit;
end;
ChildList.Clear;
hC := GetWindow(hSrc, GW_CHILD);
// if hC <> 0 then
// begin
// Inc(i);
// GetWindowRect(hC, ChildRect);
// DlgAngle_.ShowAngle(ChildRect);
//
// FindChildWnd(hC);
//
// hC := GetWindow(hC, GW_HWNDNEXT);
// _Trace(Format('Found .. Idx=%d, Cap=%s, WndClass=%s', [i, GetWindowCaption(hc), GetWndClassName(hc)]));
// end;
while hC <> 0 do
begin
llStyle := GetWindowStyle(hC);
if (llStyle and WS_VISIBLE) <> 0 then
begin
sClassName := GetWndClassName(hC);
if CompareText(sClassName, 'Chrome_RenderWidgetHostHWND') = 0 then
ChildList.Add(hC);
end;
hC := GetWindow(hC, GW_HWNDNEXT);
end;
Sleep(500);
end;
begin
Guard(ChildList, TList<HWND>.Create);
Guard(DlgAngle, TDlgAngle.Create(nil));
// while not Terminated and not GetWorkStop do
// begin
// h := FindWindow(nil, nil);
// while h <> 0 do
// begin
// llStyle := GetWindowStyle(h);
// if ((llStyle and WS_VISIBLE) <> 0) and
// ((llStyle and WS_MINIMIZE) = 0) then
// begin
// sCap := GetWindowCaption(h);
// if sCap <> '' then
// begin
// sPName := UpperCase(GetProcessNameFromWndHandle(h));
// if (sPName = 'WHALE.EXE') or (sPName = 'MSEDGE.EXE') then
// begin
// i := 0;
//// _Trace(Format('Found .. %d', [i]));
//
// FindChildWnd(h);
//
// if ChildList.Count > 1 then
// begin
// GetWindowRect(ChildList[ChildList.Count - 1], ChildRect);
// DlgAngle_.ShowAngle(ChildRect);
// end;
//
//// Sleep(500);
// end;
// end;
// end;
// h := GetWindow(h, GW_HWNDNEXT);
// end;
// end;
hOld := 0;
while not Terminated and not GetWorkStop do
begin
h := GetForegroundWindow;
// if h = hOld then
// begin
// Sleep(500);
// continue;
// end;
// hOld := h;
sPName := UpperCase(GetProcessNameFromWndHandle(h));
if (sPName <> 'WHALE.EXE') and (sPName <> 'MSEDGE.EXE') then
begin
DlgAngle_.Hide;
Sleep(500);
continue;
end;
FindChildWnd(h);
if ChildList.Count > 1 then
begin
h := ChildList[ChildList.Count - 1];
GetWindowRect(h, ChildRect);
DlgAngle_.ShowAngle(ChildRect);
// PostMessage(h, WM_CLOSE, 0, 0);
end else
DlgAngle_.Hide;
//
// if not GetWindowRect(h, MainRect) then
// begin
// Sleep(500);
// continue;
// end;
//// DlgAngle_.ShowAngle(MainRect);
//
// i := 0;
// _Trace(Format('Found .. %d', [i]));
//
// FindChildWnd(h);
Sleep(500);
end;
end;
end.