加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 10:13:00 所属栏目:大数据 来源:网络整理
导读:我需要一种方法来自定义控件(来自TCustomControl)来判断它当前是否可见.我不是在谈论.Visible属性;我的意思是它是否实际上正在屏幕上显示.有谁知道如何做到这一点? 解决方法 几年前,我对表单遇到了同样的问题:我正在寻找一种方法来确定表单是否实际可见(甚
我需要一种方法来自定义控件(来自TCustomControl)来判断它当前是否可见.我不是在谈论.Visible属性;我的意思是它是否实际上正在屏幕上显示.有谁知道如何做到这一点?

解决方法

几年前,我对表单遇到了同样的问题:我正在寻找一种方法来确定表单是否实际可见(甚至只是部分)给用户.
特别是当它应该是可见的并且显示为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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读