窗体移动(消息欺骗应用)

来源:互联网 发布:软件ico图标 编辑:程序博客网 时间:2024/05/16 17:52

通过对窗体消息WM_NCHITTEST的欺骗,使其认为鼠标位置在标题栏,进而直接对窗体(非标题栏)拖动即可移动整个窗体.

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs;type  TForm1 = class(TForm)  private    { Private declarations }    //*********************消息声明****************//    procedure wmnchittest(var msg:twmnchittest);    message wm_nchittest;    //*********************消息声明完成************//  public    { Public declarations }  end;var  Form1: TForm1;implementation{$R *.dfm}//*************************欺骗消息****************//procedure TForm1.wmnchittest(var msg:twmnchittest);begininherited;if (htclient=msg.result) then msg.result:=htcaption;//如果 在客户区内=消息.结果 则 消息.结果=在标题栏内end;//*************************欺骗消息完成************//end.

PS:

WM_NCHITTEST:当光标移动,鼠标按下或释放时发生.

htClient:(WM_NCHITTEST)值鼠标按下时产生的消息(在客户区内).

htCaption:(WM_NCHITTEST)值鼠标按下时产生的消息(在标题栏内).

inherited:继承父类同名同参数.

原创粉丝点击