S sy0116 Unregistered / Unconfirmed GUEST, unregistred user! 2006-06-28 #1 如何得到某一个窗体的left、top、width、height值?这个窗体不是我的程序中的
轻 轻舞肥羊 Unregistered / Unconfirmed GUEST, unregistred user! 2006-06-28 #4 PWindowInfo = ^TWindowInfo;<br> TWindowInfo = record<br> Enabled : Boolean;<br> Text : String;<br> ClassName : String;<br> Top : Integer;<br> Left : Integer;<br> Height : Integer;<br> Width : Integer;<br> end;<br><br>function GetWindowInfo(<br> const AHwnd : HWnd<br>  WindowInfo;<br>//取得窗口信息结构<br>var<br> rt : TRect;<br> p : TPoint;<br> hParent : HWND;<br>begin<br> New(Result);<br> with Result^ do<br> begin<br> Enabled := IsWindowEnabled(AHWnd);<br> Text := GetWindowText(AHWnd, True);<br> ClassName := GetClassName(AHWnd);<br> GetWindowRect(AHwnd, rt);<br> hParent := GetParent(AHwnd);<br> if hParent > 0 then<br> begin //子窗体 取相对于它的容器的位置而不是绝对位置<br> p.X := rt.Left;<br> p.Y := rt.Top;<br> ScreenToClient(hParent, p);<br> Left := p.X;<br> Top := p.Y;<br> end<br> else begin<br> Top := rt.Top;<br> Left := rt.Left;<br> end;<br> Width := rt.Right - rt.Left;<br> Height := rt.Bottom - rt.Top;<br> end;<br>end;
PWindowInfo = ^TWindowInfo;<br> TWindowInfo = record<br> Enabled : Boolean;<br> Text : String;<br> ClassName : String;<br> Top : Integer;<br> Left : Integer;<br> Height : Integer;<br> Width : Integer;<br> end;<br><br>function GetWindowInfo(<br> const AHwnd : HWnd<br>  WindowInfo;<br>//取得窗口信息结构<br>var<br> rt : TRect;<br> p : TPoint;<br> hParent : HWND;<br>begin<br> New(Result);<br> with Result^ do<br> begin<br> Enabled := IsWindowEnabled(AHWnd);<br> Text := GetWindowText(AHWnd, True);<br> ClassName := GetClassName(AHWnd);<br> GetWindowRect(AHwnd, rt);<br> hParent := GetParent(AHwnd);<br> if hParent > 0 then<br> begin //子窗体 取相对于它的容器的位置而不是绝对位置<br> p.X := rt.Left;<br> p.Y := rt.Top;<br> ScreenToClient(hParent, p);<br> Left := p.X;<br> Top := p.Y;<br> end<br> else begin<br> Top := rt.Top;<br> Left := rt.Left;<br> end;<br> Width := rt.Right - rt.Left;<br> Height := rt.Bottom - rt.Top;<br> end;<br>end;