delphi WinAPI: GetWindowRect、GetClientRect - 获取窗口的外部与内部矩形  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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.

//效果图:


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.055663824081421 seconds