对于没有设置WS_VISIBLE风格的窗口可以用IsWindowVisible来判断窗口是否可见。
如果我在一个Form上有两个Button:Button1和Button2。其Visible属性都是True。
但如果我将Button2覆盖在Button1上,Button1将也看不到。
对于这种Visible属性为True,但却看不到的窗口,应该怎么判断它的可见性?
我如何知道某个窗口一定是可以看到的?

解决方案 »

  1.   

    ///////////////////////////////////////////////////////////////////////////////
    //  MethodName: GetControlVisible
    //  Function  : Scan :AControl and all its parents' Visible property to find
    // it really visible
    //  Author    : Chen Jiangyong
    //  Date      : 1999/02/15
    ///////////////////////////////////////////////////////////////////////////////function GetControlVisible(const AControl: TControl): Boolean;
    var
      Parent: TWinControl;
    begin
      Result := AControl.Visible;
      Parent := AControl.Parent;
      // Search all parents' visible property
      while Parent <> nil do begin
        Result := Result and Parent.Visible;
        Parent := Parent.Parent
      end
    end;
      

  2.   

    老大,这样好像不行吧。
    我的两个Button以及它们所在的Form的Visible属性都是True。
    只是一个Button遮住了另一个。
    你这样做只是判断了控件及其父窗口的Visible属性是否都是True。
    无法知道是否一个被另一个遮住了,以及是哪个遮住了另一个。
      

  3.   

    遮住这个东西比较头痛,必须判断每个控件的Z Order,然后看看每个控件的BoundsRect是否互相覆盖,代码比上面的要复杂的多。
      

  4.   

    to chechy(为程序而奋斗):根本文不对题嘛。你的函数根本就是取控件及其parent的visible属性值;如楼主所说,button1的visible属性值为true,但被button2盖住了,看不见,而你的函数返回的一定是true。