用GetCursorPos自己判断一下鼠标位置 The GetCursorPos function retrieves the cursor's position, in screen coordinates. BOOL GetCursorPos( LPPOINT lpPoint // cursor position );
自定义消息:procedure WMNCHitTest(var Msg: TMessage); message WM_NCHITTEST; procedure TForm1.WMNCHitTest(var Msg: TMessage); begin inherited; if Msg.Result=HTCLIENT then label1.Caption:='in' else label1.Caption:='out'; end;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER; procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.CMMouseEnter(var Message: TMessage); begin case Message.Msg of CM_MOUSEENTER:begin SetCapture(Handle); if Self.Height < 100 then self.Height := 300; self.Invalidate; end; end;end;procedure TForm1.CMMouseLeave(var Message: TMessage); begin case Message.Msg of CM_MOUSELEAVE: begin if self.Height > 100 then self.Height := 50; self.Invalidate; ReleaseCapture; end; end; end;procedure TForm1.FormCreate(Sender: TObject); begin if (self.Left > 1000) and (self.Top < 50) then begin self.Height := 10; self.Refresh;
procedure TForm1.CMMouseEnter(var Message: TMessage); begin case Message.Msg of CM_MOUSEENTER:begin SetCapture(Handle); if Self.Height < 100 then self.Height := 300; self.Invalidate; end; end;end;procedure TForm1.CMMouseLeave(var Message: TMessage); begin case Message.Msg of CM_MOUSELEAVE: begin if self.Height > 100 then self.Height := 50; self.Invalidate; ReleaseCapture; end; end; end;
用消息,跟踪MouseMove所在地方的当前对象的HWND
赞同
用消息,跟踪MouseMove所在地方的当前对象的HWND
赞同
The GetCursorPos function retrieves the cursor's position, in screen coordinates. BOOL GetCursorPos(
LPPOINT lpPoint // cursor position
);
procedure TForm1.WMNCHitTest(var Msg: TMessage);
begin
inherited;
if Msg.Result=HTCLIENT then
label1.Caption:='in'
else
label1.Caption:='out';
end;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.CMMouseEnter(var Message: TMessage);
begin
case Message.Msg of
CM_MOUSEENTER:begin
SetCapture(Handle);
if Self.Height < 100 then
self.Height := 300;
self.Invalidate;
end;
end;end;procedure TForm1.CMMouseLeave(var Message: TMessage);
begin
case Message.Msg of
CM_MOUSELEAVE: begin
if self.Height > 100 then
self.Height := 50;
self.Invalidate;
ReleaseCapture;
end; end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
if (self.Left > 1000) and (self.Top < 50) then
begin
self.Height := 10;
self.Refresh;
end;
end;
前一段时间做的一个例子,比较粗糙,将就看吧(类似QQ的伸缩窗体)
2.允许鼠标操作(Click,Drag等)。
Ansha(Ansha),naughtyboy(一切都是为了明天)两位朋友的方法也不理想。
请诸位在帮我想些办法,多谢。
begin
case Message.Msg of
CM_MOUSEENTER:begin
SetCapture(Handle);
if Self.Height < 100 then
self.Height := 300;
self.Invalidate;
end;
end;end;procedure TForm1.CMMouseLeave(var Message: TMessage);
begin
case Message.Msg of
CM_MOUSELEAVE: begin
if self.Height > 100 then
self.Height := 50;
self.Invalidate;
ReleaseCapture;
end; end;
end;
HWND WindowFromPoint(
POINT Point // structure with point
);再比较Handle
也适用于异形窗体,不足之处不能以事件方式实现。
多谢各位帮忙。
就使用api了;
主要是
对鼠标和窗体进行判断!!~