***请教:关于获得鼠标悬停(WM_MOUSEHOVER / WM_NCMOUSEHOVER)消息问题

Libran 2005-03-04 04:57:13
在Windows 2000 Server + VC6 环境下:
1,在WndProc中处理 WM_MOUSEMOVE 消息,使用
TRACKMOUSEEVENT trmouse;
trmouse.dwFlags = TME_HOVER;
...
_TrackMouseEvent(&trmouse);
的方法,可以正确获得 WM_MOUSEHOVER 消息;但改为
trmouse.dwFlags = TME_HOVER | TME_NONCLIENT;
后,无论 WM_MOUSEHOVER 还是 WM_NCMOUSEHOVER 都没有反应。
应经添加了宏定义:
#define TME_NONCLIENT 0x00000010
#define WM_NCMOUSEHOVER 0x02A0
请教是何原因?又该如何解决?

2,使用 WH_MOUSE 类型的钩子,可以成功钩到 WM_MOUSEMOVE 消息;
但同样在处理 WM_MOUSEMOVE 消息中使用 TrackMouseEvent,却无法获得 WM_MOUSEHOVER 消息,是怎么回事?
难道鼠标钩子不能钩 WM_MOUSEHOVER 消息吗?
...全文
1151 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ringphone 2005-03-08
  • 打赏
  • 举报
回复
TME_NONCLIENT是非客户区消息,你在WM_MOUSEMOVE里TrackMouseEvent是没有用的,因为这样只有鼠标在客户区才会关注WM_NCMOUSEMOVE,而鼠标移到标题栏因为没有触发WM_MOUSEMOVE,就没有TrackMouseEvent,也就不会有WM_NCMOUSEMOVE消息。
你应该这样:
LRESULT CALLBACK MainWndProc(HWND hWnd,UINT uMsg,WPARAM,LPARAM)
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = hWnd;
tme.dwHoverTime = 10;//HOVER_DEFAULT;

if((uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST))
{
tme.dwFlags = TME_LEAVE | TME_HOVER;
TrackMouseEvent(&tme);
}
else if(uMsg == WM_NCHITTEST)
{
tme.dwFlags = TME_LEAVE | TME_HOVER | TME_NONCLIENT;
TrackMouseEvent(&tme);
}

switch(uMsg)
{
//窗口过程消息处理:
...
}
...
}
这样WM_MOUSEHOVER和WM_NCMOUSEHOVER就都能得到了。
Libran 2005-03-07
  • 打赏
  • 举报
回复
再UP一下,难道就没人知道么?
得不到答案的帖子能不能删掉啊?实在不想浪费可用分!
fireseed 2005-03-07
  • 打赏
  • 举报
回复
意思就是WM_MOUSEHOVER不会自动激发,要调用API才可以用

TrackMouseEvent Function

--------------------------------------------------------------------------------

The TrackMouseEvent function posts messages when the mouse pointer leaves a window or hovers over a window for a specified amount of time.

Syntax

BOOL TrackMouseEvent( LPTRACKMOUSEEVENT lpEventTrack
);
Parameters

lpEventTrack
[in, out] Pointer to a TRACKMOUSEEVENT structure that contains tracking information.
Return Value


If the function succeeds, the return value is nonzero .

If the function fails, return value is zero. To get extended error information, call GetLastError.

The function can post the following messages.


Message Meaning
WM_NCMOUSEHOVER Windows 98/Me, Windows 2000/XP: The same meaning as WM_MOUSEHOVER except this is for the nonclient area of the window.
WM_NCMOUSELEAVE Windows 98/Me, Windows 2000/XP: The same meaning as WM_MOUSELEAVE except this is for the nonclient area of the window.
WM_MOUSEHOVER The mouse hovered over the client area of the window for the period of time specified in a prior call to TrackMouseEvent. Hover tracking stops when this message is generated. The application must call TrackMouseEvent again if it requires further tracking of mouse hover behavior.
WM_MOUSELEAVE The mouse left the client area of the window specified in a prior call to TrackMouseEvent. 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.



Remarks

The mouse pointer is considered to be hovering when it stays within a specified rectangle for a specified period of time. Call SystemParametersInfo. and use the values SPI_GETMOUSEHOVERWIDTH, SPI_GETMOUSEHOVERHEIGHT, and SPI_GETMOUSEHOVERTIME to retrieve the size of the rectangle and the time.


Note The _TrackMouseEvent function calls TrackMouseEvent if it exists, otherwise _TrackMouseEvent emulates TrackMouseEvent. The _TrackMouseEvent function is in commctrl.h and is exported by COMCTRL32.DLL.

Function Information

Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 98, Windows NT 4.0

See Also

Mouse Input, SystemParametersInfo, _TrackMouseEvent, TRACKMOUSEEVENT

--------------------------------------------------------------------------------

© 2003 Microsoft Corporation. All rights reserved.

TRACKMOUSEEVENT Structure

--------------------------------------------------------------------------------

The TRACKMOUSEEVENT structure is used by the TrackMouseEvent function to track when the mouse pointer leaves a window or hovers over a window for a specified amount of time.

Syntax

typedef struct tagTRACKMOUSEEVENT {
DWORD cbSize;
DWORD dwFlags;
HWND hwndTrack;
DWORD dwHoverTime;
} TRACKMOUSEEVENT, *LPTRACKMOUSEEVENT;
Members

cbSize
Specifies the size of the TRACKMOUSEEVENT structure.
dwFlags
Specifies the services requested. This member can be a combination of the following values.
TME_CANCEL
The caller wants to cancel a prior tracking request. The caller should also specify the type of tracking that it wants to cancel. For example, to cancel hover tracking, the caller must pass the TME_CANCEL and TME_HOVER flags.
TME_HOVER
The caller wants hover notification. Notification is delivered as a WM_MOUSEHOVER message.
If the caller requests hover tracking while hover tracking is already active, the hover timer will be reset.

This flag is ignored if the mouse pointer is not over the specified window or area.

TME_LEAVE
The caller wants leave notification. Notification is delivered as a WM_MOUSELEAVE message. If the mouse is not over the specified window or area, a leave notification is generated immediately and no further tracking is performed.
TME_NONCLIENT
Windows 98/Me, Windows 2000/XP: The caller wants hover and leave notification for the nonclient areas. Notification is delivered as WM_NCMOUSEHOVER and WM_NCMOUSELEAVE messages.
TME_QUERY
The function fills in the structure instead of treating it as a tracking request. The structure is filled such that had that structure been passed to TrackMouseEvent, it would generate the current tracking. The only anomaly is that the hover time-out returned is always the actual time-out and not HOVER_DEFAULT, if HOVER_DEFAULT was specified during the original TrackMouseEvent request.
hwndTrack
Specifies a handle to the window to track.
dwHoverTime
Specifies the hover time-out (if TME_HOVER was specified in dwFlags), in milliseconds. Can be HOVER_DEFAULT, which means to use the system default hover time-out.
Remarks

The system default hover time-out is initially the menu drop-down time, which is 400 milliseconds. You can call SystemParametersInfo and use SPI_GETMOUSEHOVERTIME to retrieve the default hover time-out.

The system default hover rectangle is the same as the double-click rectangle. You can call SystemParametersInfo and use SPI_GETMOUSEHOVERWIDTH and SPI_GETMOUSEHOVERHEIGHT to retrieve the size of the rectangle within which the mouse pointer has to stay for TrackMouseEvent to generate a WM_MOUSEHOVER message.

Structure Information

Header Declared in Winuser.h, include Windows.h
Minimum operating systems Windows 98, Windows NT 4.0

See Also

Mouse Input

--------------------------------------------------------------------------------

© 2003 Microsoft Corporation. All rights reserved.
Libran 2005-03-07
  • 打赏
  • 举报
回复
up
quaiyan 2005-03-07
  • 打赏
  • 举报
回复
up
Libran 2005-03-05
  • 打赏
  • 举报
回复
up
Libran 2005-03-05
  • 打赏
  • 举报
回复
周末没人?
自己up...
Libran 2005-03-04
  • 打赏
  • 举报
回复
是我讲得不够清楚?楼上两位所讲的和我的问题关系不大啊……

总结起来就是:
1,如何触发“WM_NCMOUSEHOVER”消息?——注意:非“WM_MOUSEHOVER”消息!
关键是如何才能使“TME_NONCLIENT”标记真正起到作用、并且使“WM_NCMOUSEHOVER”消息可用?

2,能否使用“WH_MOUSE”类型的钩子来拦截“WM_MOUSEHOVER”和“WM_NCMOUSEHOVER”消息?
若能,应该如何使用?


kingzai 2005-03-04
  • 打赏
  • 举报
回复
use
TrackMouseEvent
Message Meaning
WM_MOUSEHOVER The mouse hovered over the client area of the window for the period of time specified in a prior call to TrackMouseEvent. Hover tracking stops when this message is generated. The application must call TrackMouseEvent again if it requires further tracking of mouse hover behavior.
findingit 2005-03-04
  • 打赏
  • 举报
回复
你就试一下:
TRACKMOUSEEVENT trmouse;
trmouse.dwFlags = TME_NONCLIENT;
...
_TrackMouseEvent(&trmouse);

你的疑问不就可以知道了吗?

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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