gpt4 book ai didi

delphi - 我如何判断 Delphi 控件当前是否可见?

转载 作者:行者123 更新时间:2023-12-03 14:42:51 25 4
gpt4 key购买 nike

我需要一种方法来让自定义控件(从 TCustomControl 派生)来判断它当前是否可见。我不是在谈论 .Visible 属性;我的意思是它目前是否实际显示在屏幕上。有谁知道该怎么做吗?

最佳答案

几年前,我在表单方面遇到了同样的问题:我正在寻找一种方法来确定表单是否实际上对用户可见(即使只是部分可见)。
特别是当它应该是可见的并且 Showing 为 True 但窗口实际上完全位于另一个窗口后面时。
这是代码,它可以适用于 WinControl...

{----------------------------------------------------------}
function IsMyFormCovered(const MyForm: TForm): Boolean;
var
MyRect: TRect;
MyRgn, TempRgn: HRGN;
RType: Integer;
hw: HWND;
begin
MyRect := MyForm.BoundsRect; // screen coordinates
MyRgn := CreateRectRgnIndirect(MyRect); // MyForm not overlapped region
hw := GetTopWindow(0); // currently examined topwindow
RType := SIMPLEREGION; // MyRgn type

// From topmost window downto MyForm, build the not overlapped portion of MyForm
while (hw<>0) and (hw <> MyForm.handle) and (RType <> NULLREGION) do
begin
// nothing to do if hidden window
if IsWindowVisible(hw) then
begin
GetWindowRect(hw, MyRect);
TempRgn := CreateRectRgnIndirect(MyRect);// currently examined window region
RType := CombineRgn(MyRgn, MyRgn, TempRgn, RGN_DIFF); // diff intersect
DeleteObject( TempRgn );
end; {if}
if RType <> NULLREGION then // there's a remaining portion
hw := GetNextWindow(hw, GW_HWNDNEXT);
end; {while}

DeleteObject(MyRgn);
Result := RType = NULLREGION;
end;

function IsMyFormVisible(const MyForm : TForm): Boolean;
begin
Result:= MyForm.visible and
isWindowVisible(MyForm.Handle) and
not IsMyFormCovered(MyForm);
end;

关于delphi - 我如何判断 Delphi 控件当前是否可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/646527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com