通过对窗体消息WM_NCHITTEST的欺骗,使其认为鼠标位置在标题栏,进而直接对窗体(非标题栏)拖动即可移动整个窗体.
unit Unit1;
interface
uses
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);
begin
inherited;
if (htclient=msg.result) then msg.result:=htcaption;//如果 在客户区内=消息.结果 则 消息.结果=在标题栏内
end;
//*************************欺骗消息完成************//
end.
PS:
WM_NCHITTEST:当光标移动,鼠标按下或释放时发生.
htClient:(WM_NCHITTEST)值鼠标按下时产生的消息(在客户区内).
htCaption:(WM_NCHITTEST)值鼠标按下时产生的消息(在标题栏内).
inherited:继承父类同名同参数.