BorderStyle=bsNone的窗口,我想拖动边缘改变大小,看看别人的网站说可以截取消
> 息,替换hittest,可是怎么试也不行。请高手支招,谢谢!
>
确实是要截取nchittest消息现在源码附上:
程序中词句未优化。。
unit Resize;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
lpRect:TRect;
mess1:string;
procedure hitit(var msg:TWMNCHITTEST);
message WM_NCHITTEST;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.hitit(var msg: TWMNCHITTEST);
var
pt:TPoint;
begin
pt.x:=msg.XPos;
pt.y:=msg.YPos;
pt:=ScreenToClient(pt);
if ptInRect(Rect(lpRect.Right-5,lpRect.Top+5,
lpRect.Right+5,lpRect.Bottom-5),pt) then
msg.Result:=HTRIGHT; file://右边
if ptInRect(Rect(lpRect.Left-5,lpRect.Top+5,
lpRect.Left+5,lpRect.Bottom-5),pt) then
msg.Result:=HTLEFT; file://左边
if ptInRect(Rect(lpRect.Left+5,lpRect.Top-5,
lpRect.Right-5,lpRect.Top+5),pt) then
msg.Result:=HTTOP; file://上边
if ptInRect(Rect(lpRect.Left+5,lpRect.Bottom-5,
lpRect.Right-5,lpRect.Bottom+5),pt) then
msg.Result:=HTBOTTOM; file://下边
if ptinRect(Rect(lpRect.Left-5,lpRect.Top-5,
lpRect.Left+5,lpRect.Top+5),pt) then
msg.Result:=HTTOPLEFT; file://左上角
if ptInRect(Rect(lpRect.Right-5,lpRect.Bottom-5,
lpRect.Right+5,lpRect.Bottom+5),pt) then
msg.Result:=HTBOTTOMRIGHT; file://右下角
if ptInRect(Rect(lpRect.Left-5,lpRect.Bottom-5,
lpRect.Left+5,lpRect.Bottom+5),pt) then
msg.Result:=HTBOTTOMLEFT; file://左下角
if ptInRect(Rect(lpRect.Right-5,lpRect.Left-5,
lpRect.Right+5,lpRect.Left+5),pt) then
msg.Result:=HTTOPRIGHT; file://右上角
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
lpRect:=ClientRect;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
lpRect:=ClientRect;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
end.
yugz@263.net