如何得到某一个窗体的left、top、width、height值?(20分)

  • 主题发起人 主题发起人 sy0116
  • 开始时间 开始时间
S

sy0116

Unregistered / Unconfirmed
GUEST, unregistred user!
如何得到某一个窗体的left、top、width、height值?这个窗体不是我的程序中的
 
属性里不就能获得?
 
这个窗体不是我的程序中的阿,怎么看属性?
 
PWindowInfo = ^TWindowInfo;<br> &nbsp;TWindowInfo = record<br> &nbsp; &nbsp;Enabled &nbsp; &nbsp; : Boolean;<br> &nbsp; &nbsp;Text &nbsp; &nbsp; &nbsp; &nbsp;: String;<br> &nbsp; &nbsp;ClassName &nbsp; : String;<br> &nbsp; &nbsp;Top &nbsp; &nbsp; &nbsp; &nbsp; : Integer;<br> &nbsp; &nbsp;Left &nbsp; &nbsp; &nbsp; &nbsp;: Integer;<br> &nbsp; &nbsp;Height &nbsp; &nbsp; &nbsp;: Integer;<br> &nbsp; &nbsp;Width &nbsp; &nbsp; &nbsp; : Integer;<br> &nbsp;end;<br><br>function GetWindowInfo(<br> &nbsp; &nbsp;const AHwnd : HWnd<br> &nbsp; &nbsp;):PWindowInfo;<br>//取得窗口信息结构<br>var<br> &nbsp;rt &nbsp;: TRect;<br> &nbsp;p : TPoint;<br> &nbsp;hParent : HWND;<br>begin<br> &nbsp;New(Result);<br> &nbsp;with Result^ do<br> &nbsp;begin<br> &nbsp; &nbsp;Enabled &nbsp; := &nbsp;IsWindowEnabled(AHWnd);<br> &nbsp; &nbsp;Text &nbsp; &nbsp; &nbsp;:= &nbsp;GetWindowText(AHWnd, True);<br> &nbsp; &nbsp;ClassName := &nbsp;GetClassName(AHWnd);<br> &nbsp; &nbsp;GetWindowRect(AHwnd, rt);<br> &nbsp; &nbsp;hParent := &nbsp;GetParent(AHwnd);<br> &nbsp; &nbsp;if hParent &gt; 0 then<br> &nbsp; &nbsp;begin //子窗体 取相对于它的容器的位置而不是绝对位置<br> &nbsp; &nbsp; &nbsp;p.X := &nbsp;rt.Left;<br> &nbsp; &nbsp; &nbsp;p.Y := &nbsp;rt.Top;<br> &nbsp; &nbsp; &nbsp;ScreenToClient(hParent, p);<br> &nbsp; &nbsp; &nbsp;Left &nbsp;:= &nbsp;p.X;<br> &nbsp; &nbsp; &nbsp;Top := &nbsp;p.Y;<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else begin<br> &nbsp; &nbsp; &nbsp;Top &nbsp; := &nbsp;rt.Top;<br> &nbsp; &nbsp; &nbsp;Left &nbsp;:= &nbsp;rt.Left;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;Width := &nbsp;rt.Right - rt.Left;<br> &nbsp; &nbsp;Height &nbsp;:= &nbsp;rt.Bottom - rt.Top;<br> &nbsp;end;<br>end;
 
接受答案了.
 
后退
顶部