2024年3月21日发(作者:)
获取窗口矩形的几种方法
其中GetClientRect、ClientRect获取的是窗口的客户区矩形;
GetWindowRect、BoundsRect是获取窗口矩形;
另外,还有一个entRect(使用方法同GetWindowRect,它们都是API函数),
这里使用的GetClientRect是entRect.
本例效果图:
unitUnit1;
interface
uses
Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
Dialogs,StdCtrls;
type
TForm1=class(TForm)
procedureFormCreate(Sender:TObject);
procedureFormPaint(Sender:TObject);
procedureFormResize(Sender:TObject);
end;
var
Form1:TForm1;
implementation
{$R*.dfm}
eate(Sender:TObject);
begin
Color:=clWhite;
end;
int(Sender:TObject);
const
str='L:%d;T:%d;R:%d;B:%d-';
var
R1,R2,R3,R4:TRect;
buf:array[Byte]ofChar;
x,y,h:Integer;
begin
R1:=GetClientRect;
R2:=Rect;
GetWindowRect(Handle,R3);
R4:=Rect;
x:=10;
y:=10;
h:=10;
Randomize;
:=Random($FFFFFF);
wvsprintf(buf,str+'GetClientRect',@R1);
t(x,y,buf);
y:=y+h+ight(buf);
wvsprintf(buf,str+'Rect',@R2);
t(x,y,buf);
y:=y+h+ight(buf);
:=Random($FFFFFF);
wvsprintf(buf,str+'GetWindowRect',@R3);
t(x,y,buf);
y:=y+h+ight(buf);
wvsprintf(buf,str+'Rect',@R4);
t(x,y,buf);
end;
size(Sender:TObject);
begin
Repaint;
end;
End.
原文地址:/book/7/
发布评论