首页  编辑  

标题栏的右击

Tags: /超级猛料/VCL/Form,窗体/标题栏和边框/   Date Created:

拦截WM_NCRBUTTONDOWN;即可!

如果只想拦截在form右边三个按钮上的右击事件,则应该拦截WM_NCRBUTTONUP!

private

 procedure WMNCRBUTTONDOWN(var msg: TMessage); message WM_NCRBUTTONDOWN;

 procedure WMNCLBUTTONDOWN(var msg: TMessage); message WM_NCLBUTTONDOWN;

 procedure WMNCLBUTTONDBLCLK(var msg: TMessage); message WM_NCLBUTTONDBLCLK;

end;

implementation

procedure TForm1.WMNCRBUTTONDOWN(var msg: TMessage);

begin

 if msg.wParam = HTCAPTION then Caption := 'Right Click!';

 // Message.Result := 0; {to ignore the message}

 inherited;

end;

procedure TForm1.WMNCLBUTTONDOWN(var msg: TMessage);

begin

 if msg.wParam = HTCAPTION then Caption := 'Left Click!';

 // Message.Result := 0; {to ignore the message}

 inherited;

end;

procedure TForm1.WMNCLBUTTONDBLCLK(var msg: TMessage);

begin

 if msg.wParam = HTCAPTION then Caption := 'Double Click!';

 // Message.Result := 0; {to ignore the message}

 inherited;

end;

*********************************

Simple method from Nail

...

interface

TForm1 = class(TForm)

...

private

procedure WMNCHitTest(var message:TWMNCHitTest); message WM_NCHITTEST;

...

implementation

...

procedure TForm1.WMNCHitTest(var message:TWMNChitTest);

begin

if message.result = HT_CAPTION then

begin

...

end;

end;

...