一个有关CM_MouseLeave的问题

oldhawk 2002-01-04 09:28:55
CM_MouseLeave消息好象不太灵敏,当鼠标快速移出窗体时,就收不到这个消息,请问大家有什么好办法吗?
...全文
450 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
oldhawk 2002-01-07
  • 打赏
  • 举报
回复
浪人:
在我的WINDOWS98S上测了一下,十分灵敏,感激不尽!分都给你了。
后会有期!
VSaber 2002-01-07
  • 打赏
  • 举报
回复
to oldhawk(老鹰):上面贴一大堆东西,不好意思,因为我对他有点生气而已,呵呵
给你的代码,很简单,值得注意的就一点,TrackMouseEvent的调用在窗体的mousemove里面,good lucky!!!:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }

procedure MouseLeave(var Msg: TMessage); message WM_MOUSELEAVE;

public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
xh: TTrackMouseEvent;
begin
xh.cbSize := sizeof(xh);
xh.dwFlags := TME_LEAVE;
xh.hwndTrack := Handle;
xh.dwHoverTime := 0;
TrackMouseEvent(xh);
end;

procedure TForm1.MouseLeave(var Msg: TMessage);
begin
Caption := Caption + '#';
Msg.Result := 0;
end;

end.
VSaber 2002-01-07
  • 打赏
  • 举报
回复
to ss(雅龙):
至于我是不是瞎搞,你把你的msdn换正版把,难道你的msdn和我的不一样,奇怪!WM_MOUSELEAVE到底是不是windows消息,我给你看看,我现在还用不上win64,不好意思:
下面是msdn拷贝,自己看看吧:

Platform SDK: Windows User Interface
WM_MOUSELEAVE
The WM_MOUSELEAVE message is posted to a window when the cursor leaves the client area of the window specified in a prior call to TrackMouseEvent.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_MOUSELEAVE
WPARAM wParam, // not used
LPARAM lParam // not used
);
Parameters
This message has no parameters.

Return Values
If an application processes this message, it should return zero.

Remarks
All tracking requested by TrackMouseEvent is canceled when this message is generated. The application must call TrackMouseEvent when the mouse reenters its window if it requires further tracking of mouse hover behavior.

Requirements
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 98 or later.
Header: Declared in Winuser.h; include Windows.h.

See Also
Mouse Input Overview, Mouse Input Messages, GetCapture, SetCapture, TrackMouseEvent, TRACKMOUSEEVENT, WM_NCMOUSELEAVE

Built on Thursday, October 12, 2000Requirements
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 98 or later.
Header: Declared in Winuser.h; include Windows.h.
See Also
Mouse Input Overview, Mouse Input Messages, GetCapture, SetCapture, TrackMouseEvent, TRACKMOUSEEVENT, WM_NCMOUSELEAVE
oldhawk 2002-01-06
  • 打赏
  • 举报
回复
先谢了。
另外说一句,我刚试了用SetCapture的方法,但效果不好。
ss 2002-01-06
  • 打赏
  • 举报
回复
.net中有这个消息啊
ss 2002-01-06
  • 打赏
  • 举报
回复
wm_mouseleave是windows的消息吗?瞎搞嘛!你说的是win64还是win32啊
VSaber 2002-01-06
  • 打赏
  • 举报
回复
明天给你一个例子
oldhawk 2002-01-06
  • 打赏
  • 举报
回复
但我手边的DELPHI 5的WIN REFERENCE手册中trackmouseevent的QUICKINFO明确指出不支持。
浪人,能让我看看你的代码吗?我的代码如下:

procedure TForm1.Button1Click(Sender: TObject);
var
e: TagTRACKMOUSEeVENT;
begin
E.cbSize:= SIZEof(TagTRACKMOUSEeVENT);
E.dwFlags:= TME_LEAVE;
E.dwHoverTime:= 10;
E.hwndTrack:= handle;
trackmouseevent(e);
end;

procedure TForm1.WMMouseLeave(var M: TMessage);
begin
color:= clRed;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
color:= clBlue;
end;

不行。
VSaber 2002-01-06
  • 打赏
  • 举报
回复
不会呀,trackmouseevent虽然我没在98下测试,但是msdn上说了支持98,不要告诉我ms在骗我:)呵呵

Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 98 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.
oldhawk 2002-01-05
  • 打赏
  • 举报
回复
好象不行,trackmouseevent是NT的函数。
我在98下试了试,没有反应。
VSaber 2002-01-04
  • 打赏
  • 举报
回复
wm_mouseleave是windows的消息,我测试过处理mouseleave绝对很不错,虽然必须结合trackmouseevent函数使用,不是很方便,但是效果嘛,最好!
yuiac 2002-01-04
  • 打赏
  • 举报
回复
我正好有同样的问题,上面几位的意见都不一样,能不能说的详细一点。
sky_line 2002-01-04
  • 打赏
  • 举报
回复
使用wndpro函数
qiubolecn 2002-01-04
  • 打赏
  • 举报
回复
要SetCapture
VSaber 2002-01-04
  • 打赏
  • 举报
回复
cm_mouseleave的确不太好用,应该用wm_mouseleave这个消息结合trackmouseevent这个api使用!绝对好用,呵呵,只不过比cm_mouseleave麻烦一点点了!
oldhawk 2002-01-04
  • 打赏
  • 举报
回复
移出窗体了,不行。
enlightenment 2002-01-04
  • 打赏
  • 举报
回复

那就用上一级组件的CM_MouseEnter配合

5,531

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧