如何模拟从一个窗口到另一个窗口的鼠标移动事件?
我正在尝试创建一个空窗口,在WinProc中处理WM_MOUSEMOVE消息:
case WM_MOUSEMOVE:
{
HWND otherHwnd = HWND(0x000608FC);
POINT pt = {LOWORD(lParam), HIWORD(lParam)};
ClientToScreen(otherHwnd, &pt);
PostMessage(otherHwnd, WM_TIMER, WPARAM(4096), 0);
PostMessage(otherHwnd, message, wParam, lParam);
SendMessage(otherHwnd, WM_NCHITTEST, NULL, (LPARAM)MAKELONG(pt.x, pt.y));
SendMessage(otherHwnd, WM_NCHITTEST, NULL, (LPARAM)MAKELONG(pt.x, pt.y));
SendMessage(otherHwnd, WM_NCHITTEST, NULL, (LPARAM)MAKELONG(pt.x, pt.y));
SendMessage(otherHwnd, WM_SETCURSOR, WPARAM(otherHwnd), (LPARAM)MAKELONG(HTCLIENT, WM_MOUSEMOVE));
break;
}
我希望我可以将超链接悬停在IE中,但结果是超链接仅在很短的时间内显示为悬停样式,然后就变成正常了,然后再次悬停,则正常。 在 www.amazon.com 上,当我模拟悬停链接(“Today's Deals”)时,该链接正在闪烁。
我认为有一个更好的方法可以做到这一点,即使IE窗口被其他一些窗口覆盖,它也可以使IE与mouseevent一起动作。等待最佳解决方案~ orz
上面是我真正悬停链接时的间谍++日志。 模拟信息与真实信息相同
<01277> 000608FC S WM_SETCURSOR hwnd:000608FC nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<01278> 000608FC R WM_SETCURSOR fHaltProcessing:False
<01279> 000608FC P WM_MOUSEMOVE fwKeys:0000 xPos:406 yPos:50
<01280> 000608FC P WM_TIMER wTimerID:4096 tmprc:00000000
<01281> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01282> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01283> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01284> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01285> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01286> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01287> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01288> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01289> 000608FC S WM_SETCURSOR hwnd:000608FC nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<01290> 000608FC R WM_SETCURSOR fHaltProcessing:False
<01291> 000608FC P WM_MOUSEMOVE fwKeys:0000 xPos:406 yPos:50
<01292> 000608FC P WM_TIMER wTimerID:4096 tmprc:00000000
<01293> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01294> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01295> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01296> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01297> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01298> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01299> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01300> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01301> 000608FC S WM_SETCURSOR hwnd:000608FC nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<01302> 000608FC R WM_SETCURSOR fHaltProcessing:False
<01303> 000608FC P WM_MOUSEMOVE fwKeys:0000 xPos:406 yPos:50
<01304> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01305> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01306> 000608FC P WM_TIMER wTimerID:4096 tmprc:00000000
<01307> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01308> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01309> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01310> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01311> 000608FC S WM_NCHITTEST xPos:521 yPos:281
<01312> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
I am trying to Create an empty window, which process the WM_MOUSEMOVE message in WinProc:
case WM_MOUSEMOVE:
{
HWND otherHwnd = HWND(0x000608FC);
POINT pt = {LOWORD(lParam), HIWORD(lParam)};
ClientToScreen(otherHwnd, &pt);
PostMessage(otherHwnd, WM_TIMER, WPARAM(4096), 0);
PostMessage(otherHwnd, message, wParam, lParam);
SendMessage(otherHwnd, WM_NCHITTEST, NULL, (LPARAM)MAKELONG(pt.x, pt.y));
SendMessage(otherHwnd, WM_NCHITTEST, NULL, (LPARAM)MAKELONG(pt.x, pt.y));
SendMessage(otherHwnd, WM_NCHITTEST, NULL, (LPARAM)MAKELONG(pt.x, pt.y));
SendMessage(otherHwnd, WM_SETCURSOR, WPARAM(otherHwnd), (LPARAM)MAKELONG(HTCLIENT, WM_MOUSEMOVE));
break;
}
I hope I can hover the hyberlink in IE, but result is the hyberlink only be showed as hover style in a very short time, then it turn to normal, and then again hover, then normal.
At www.amazon.com, when I simulate to hover the link("Today's Deals ") , the link is blinking.
I think there is a better way to do it, even the IE window is covered with some other windows, it can make the IE act with the mouseevent. waiting for the best solution~
orz
Above is the spy++ logs when I realy hover the link.
and the simulate is as same as the real message
<01277> 000608FC S WM_SETCURSOR hwnd:000608FC nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<01278> 000608FC R WM_SETCURSOR fHaltProcessing:False
<01279> 000608FC P WM_MOUSEMOVE fwKeys:0000 xPos:406 yPos:50
<01280> 000608FC P WM_TIMER wTimerID:4096 tmprc:00000000
<01281> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01282> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01283> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01284> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01285> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01286> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01287> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01288> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01289> 000608FC S WM_SETCURSOR hwnd:000608FC nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<01290> 000608FC R WM_SETCURSOR fHaltProcessing:False
<01291> 000608FC P WM_MOUSEMOVE fwKeys:0000 xPos:406 yPos:50
<01292> 000608FC P WM_TIMER wTimerID:4096 tmprc:00000000
<01293> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01294> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01295> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01296> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01297> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01298> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01299> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01300> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01301> 000608FC S WM_SETCURSOR hwnd:000608FC nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<01302> 000608FC R WM_SETCURSOR fHaltProcessing:False
<01303> 000608FC P WM_MOUSEMOVE fwKeys:0000 xPos:406 yPos:50
<01304> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01305> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01306> 000608FC P WM_TIMER wTimerID:4096 tmprc:00000000
<01307> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01308> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01309> 000608FC S WM_NCHITTEST xPos:520 yPos:283
<01310> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
<01311> 000608FC S WM_NCHITTEST xPos:521 yPos:281
<01312> 000608FC R WM_NCHITTEST nHittest:HTCLIENT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为IE调用WindowFromPoint()来获取前台窗口,如果结果不是你的IE窗口,它就知道你的鼠标不在那里。一个可能的解决方案是挂钩 API。
This is because IE calls WindowFromPoint() to obtain the foreground window, if the result is not your IE window, it knows your mouse isn't there. A possible solution is to hook the API.
你的代码没有任何问题。问题在于 Windows 发送消息的方式。
当您移动鼠标时,Windows 会将消息发送到屏幕上的每个窗口。因此,每当您向 IE 窗口句柄发送
WM_MOUSEMOVE
消息时,Windows 本身就会发送另一个消息,告知鼠标不存在。所以这是一场小比赛...
There's nothing wrong with your code. The problem is with the way Windows send messages.
As you move your mouse, Windows dispatches messages to every and all windows on screen. So whenever you send the
WM_MOUSEMOVE
message to the IE windows handle, Windows itself send another telling that the mouse isn't there.So it's a little race...