提示:
1、其实用 Delphi 内部同类函数很方便的, 但系统函数是全局的;
2、使用 GetClientRect 时, 一般要 Windows.GetClientRect, 因为 TForm 的父类有同名函数.
//声明:

{获取窗口外部矩形(相对于屏幕)}
GetWindowRect(
  hWnd: HWND;       {窗口句柄}
  var lpRect: TRect {用于返回的矩形指针}
): BOOL;

{获取窗口内部矩形}
GetClientRect(
  hWnd: HWND;       {窗口句柄}
  var lpRect: TRect {用于返回的矩形指针}
): BOOL;

//举例: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; procedure FormShow(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormShow(Sender: TObject); var r: TRect; begin GetWindowRect(Handle, r); Label1.Caption := Format('%d,%d,%d,%d', [r.Left,r.Top,r.Right,r.Bottom]); Windows.GetClientRect(Handle, r); Label2.Caption := Format('%d,%d,%d,%d', [r.Left,r.Top,r.Right,r.Bottom]); end; end. //效果图:


posted on 2008-03-10 00:19  万一  阅读(8811)  评论(0编辑  收藏  举报