点击窗体任何部分都可拖动实现后出现的问题!(50分)

  • 主题发起人 主题发起人 bevy
  • 开始时间 开始时间
B

bevy

Unregistered / Unconfirmed
GUEST, unregistred user!
使用了API的消息,程序如下:
procedure TForm1.WMNCHitTest(var M: TWMNCHitTest);
begin
inherited;
{ call the inherited message handler }
if M.Result = htClient then
{ is the click in the client area? }
M.Result := htCaption;
{ if so, make Windows think it's }
{ on the caption bar. }
end;

现在的问题是:好像窗体不能相应任何鼠标移动和点击了,比如我想设定点击窗体的
某一块位置后,窗体就关闭,但是窗体感应不到mousedown这个事件了,请问怎么办?
谢谢
 
这个例子你试试,它可以实现你的要求,而且也响应mousedown事件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
public
procedure AppMessage(var Msg:TMsg;var Handled:Boolean);
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=AppMessage;
end;

procedure TForm1.AppMessage(var Msg:TMsg;var
Handled:Boolean);
begin
if Msg.message=WM_LButtonDown then
begin
if DefWindowProc(Handle,WM_NCHitTest,0,GetMessagePos)=HTClient then
begin
SendMessage(Handle,WM_NCLButtonDown,HTCaption,GetMessagePos);
end;
end;
end;
procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
label1.caption:='ok';
end;

end.
 
接受答案了.
 
后退
顶部