本人已通过下面两个过程实现了无标题栏且可以拖动的功能
但无法实现弹出式菜单TForm =class(TForm)
...
private
procedure CreateParams(var Params:TCreateParams);override;
procedure WMNChitTest(var Msg:TWMNChitTest);Message WM_NChitTest;
public
...
var
Form1:TForm
procedure TForm.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
with Params do
Style :=(Style or WS_Popup)and (not WS_DLGFrame);
end;procedure TForm.WMNChitTest(var Msg: TWMNChitTest);
begin
inherited;
if (Msg.Result=htClient) then
Msg.Result :=htCaption;
end;
但无法实现弹出式菜单TForm =class(TForm)
...
private
procedure CreateParams(var Params:TCreateParams);override;
procedure WMNChitTest(var Msg:TWMNChitTest);Message WM_NChitTest;
public
...
var
Form1:TForm
procedure TForm.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
with Params do
Style :=(Style or WS_Popup)and (not WS_DLGFrame);
end;procedure TForm.WMNChitTest(var Msg: TWMNChitTest);
begin
inherited;
if (Msg.Result=htClient) then
Msg.Result :=htCaption;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;type
TForm1 = class(TForm)
PopupMenu: TPopupMenu;
MenuItem1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure MenuItem1Click(Sender: TObject);
private
{ Private declarations }
ACTMENU :Boolean;
procedure CreateParams(var Params:TCreateParams);override;
procedure WMNCHitTest(var Msg :TWMNCHITTEST);Message WM_NCHITTEST;
procedure WMRBUTTON(Var Msg :TWMNCRButtonDown);Message WM_NCRButtonDown;
procedure AppMessage(var Msg:TMsg;var Handled:Boolean); public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=AppMessage;
end;procedure TForm1.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
with Params do
Style :=(Style or WS_Popup)and (not WS_DLGFrame);end;procedure TForm1.WMNCHitTest(var Msg :TWMNCHITTEST);
begin
inherited;
if not ACTMENU then
Msg.Result :=htCaption
else
begin
Msg.Result :=htClient;
end;
end;procedure TForm1.WMRBUTTON(Var Msg :TWMNCRButtonDown);
begin
inherited;
Msg.Result :=htClient;
ACTMENU :=TRUE
end;procedure TForm1.AppMessage(var Msg:TMsg;var Handled:Boolean);
begin ACTMENU :=False;
if (Msg.message=WM_RButtonDown) then
begin
SendMessage(Handle,WM_RButtonDown,htClient,GetMessagePos);
Handled:=true;
end
else if (Msg.message=WM_LBUTTONDOWN )and (Msg.message=WM_MOUSEMOVE) then
begin SendMessage(Handle,WM_NCHITTEST,htCaption,GetMessagePos);
Handled :=TRUE;
end ;end;procedure TForm1.MenuItem1Click(Sender: TObject);
begin
showmessage('FFFF');
end;end.