Delphi WinAPI: GetWindowRect、GetClientRect - 获取窗口的外部与内部矩形


本文整理自网络,侵删。

 
WinAPI: GetWindowRect、GetClientRect - 获取窗口的外部与内部矩形
提示:
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.

//效果图:

相关阅读 >>

Delphi外挂编写

Delphi edit,memo中禁用ctrl+v

Delphi6-xe5 中的md5实现方法

Delphi控件升级

Delphi 取得文件夹及下一级文件夹下的文件列表

Delphi 下的通配符查找函数

Delphi textfile utf8编码读写

md5.pas

Delphi 加载图像并压缩,旋转图像角度

Delphi 泛型 tdictionary<string,string>

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...