如何从一个窗口到另一个窗口模拟mousemove事件?

时间:2010-01-18 12:36:49

标签: winapi messaging sendmessage

我正在尝试创建一个空窗口,它在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中悬停hyberlink,但结果是hyberlink只能在很短的时间内显示为悬停风格,然后转为正常,然后再次悬停,然后正常。 在www.amazon.com上,当我模拟悬停链接时(“今日特卖”),链接闪烁。

我认为有一种更好的方法可以做到这一点,即使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

2 个答案:

答案 0 :(得分:1)

这是因为IE调用WindowFromPoint()来获取前台窗口,如果结果不是你的IE窗口,它就知道你的鼠标不在那里。一种可能的解决方案是挂钩API。

答案 1 :(得分:0)

您的代码没有任何问题。问题在于Windows发送消息的方式。

当您移动鼠标时,Windows会将消息发送到屏幕上的每个窗口。因此,无论何时将WM_MOUSEMOVE消息发送到IE窗口句柄,Windows本身都会发送另一条消息,告知鼠标不在那里。

所以这是一场小小的比赛......