SendMessage单击非客户端项目

时间:2023-01-28 07:29:48

I am having trouble getting SendMessage to activate a menu on another program. When looking through Spy++ when a user clicks on the menu the following occurs:

我无法让SendMessage激活另一个程序的菜单。当用户点击菜单查看Spy ++时,会发生以下情况:

 000A0628 P WM_NCLBUTTONDOWN nHittest:HTMENU xPos:1706 yPos:395 [wParam:00000005 lParam:018B06AA time:27:23:56.156 point:(1706, 395)]
 000A0628 S WM_SYSCOMMAND uCmdType:SC_MOUSEMENU xPos:1706 yPos:395 [wParam:0000F095 lParam:018B06AA]
 000A0628 S WM_ENTERMENULOOP fIsTrackPopupMenu:False [wParam:00000000 lParam:00000000]
 000A0628 R WM_ENTERMENULOOP lResult:00000000
 000A0628 S WM_SETCURSOR hwnd:000A0628 nHittest:HTCAPTION wMouseMsg:0000 [wParam:000A0628 lParam:00000002]
 000A0628 R WM_SETCURSOR fHaltProcessing:False [lResult:00000000]
 000A0628 S WM_INITMENU hmenuInit:00200355 [wParam:00200355 lParam:00000000]
 000C0672 S EM_GETSEL lpdwStart:0010EFA0 lpdwEnd:0010EFA4 [wParam:0010EFA0 lParam:0010EFA4]
 000C0672 R EM_GETSEL wStart:26 wEnd:26 lpdwStart:0010EFA0 (684) lpdwEnd:0010EFA4 (276) [lResult:001A001A]
 000C0672 S WM_GETTEXTLENGTH wParam:00000000 lParam:00000000
 000C0672 R WM_GETTEXTLENGTH cch:26 [lResult:0000001A]
 000C0672 S EM_CANUNDO wParam:00000000 lParam:00000000
 000C0672 R EM_CANUNDO fCanUndo:True [lResult:00000001]
 000A0628 R WM_INITMENU lResult:00000000
 000A0628 S WM_MENUSELECT uItem:0 fuFlags:MF_POPUP | MF_HILITE | MF_MOUSESELECT hmenu:00200355 [wParam:80900000 lParam:00200355]
 000A0628 R WM_MENUSELECT lResult:00000000
 000A0628 S WM_INITMENUPOPUP hmenuPopup:00150595 uPos:0 fSystemMenu:False [wParam:00150595 lParam:00000000]
 000A0628 R WM_INITMENUPOPUP lResult:00000000

Whereas when I attempt the same using SendMessage with WM_NCLBUTTONDOWN the following happens instead:

而当我使用带有WM_NCLBUTTONDOWN的SendMessage尝试相同时,会发生以下情况:

 000A0628 P WM_NCLBUTTONDOWN nHittest:HTMENU xPos:1700 yPos:400 [wParam:00000005 lParam:019006A4 time:27:25:02.156 point:(1700, 400)]
 000A0628 S WM_SYSCOMMAND uCmdType:SC_MOUSEMENU xPos:1700 yPos:400 [wParam:0000F095 lParam:019006A4]
 000A0628 S WM_ENTERMENULOOP fIsTrackPopupMenu:False [wParam:00000000 lParam:00000000]
 000A0628 R WM_ENTERMENULOOP lResult:00000000
 000A0628 S WM_EXITMENULOOP fIsTrackPopupMenu:False [wParam:00000000 lParam:00000000]
 000A0628 R WM_EXITMENULOOP lResult:00000000
 000A0628 S WM_MENUSELECT uItem:0 fuFlags:FFFF (menu was closed) hmenu:00000000 [wParam:FFFF0000 lParam:00000000]
 000A0628 R WM_MENUSELECT lResult:00000000
 000A0628 S WM_EXITMENULOOP fIsTrackPopupMenu:False [wParam:00000000 lParam:00000000]
 000A0628 R WM_EXITMENULOOP lResult:00000000
 000A0628 R WM_SYSCOMMAND lResult:00000000

Does anyone know how to get this to work properly?

有谁知道如何正常工作?

Cheers

Ross

3 个解决方案

#1


I'd guess that the menu loop tests for the state of the mouse button. However, you haven't simulated pressing the mouse button, all you're doing is sending a message saying that the button is down.

我猜测菜单循环测试鼠标按钮的状态。但是,您还没有模拟按下鼠标按钮,您所做的只是发送一条消息说按钮已关闭。

If you need synchronous behavior, I would suggest a windows hook and have your thread block until the right time. (In other words, you can use an asynchronous approach and then wrap it so that it blocks and acts as a synchronous call. It's extra work, but if you insist on synchronous behavior from something that is inherently asynchronous, it's your best solution.)

如果你需要同步行为,我会建议一个Windows钩子,让你的线程阻塞到正确的时间。 (换句话说,你可以使用异步方法然后将其包装起来,以便它阻塞并充当同步调用。这是额外的工作,但如果你坚持同步行为来自本质上异步的东西,那么这是你最好的解决方案。)

#2


You shouldn't use SendMessage to simulate mouse clicks and key presses. Use SendInput instead.

您不应该使用SendMessage来模拟鼠标点击和按键。请改用SendInput。

#3


You can perfectly use SendMessage(), in particular for menus (see MSDN and Google Groups for code samples)
(and hooks have nothing to do here)

您可以完美地使用SendMessage(),特别是菜单(请参阅MSDN和Google Groups以获取代码示例)(并且钩子在此处无关)

#1


I'd guess that the menu loop tests for the state of the mouse button. However, you haven't simulated pressing the mouse button, all you're doing is sending a message saying that the button is down.

我猜测菜单循环测试鼠标按钮的状态。但是,您还没有模拟按下鼠标按钮,您所做的只是发送一条消息说按钮已关闭。

If you need synchronous behavior, I would suggest a windows hook and have your thread block until the right time. (In other words, you can use an asynchronous approach and then wrap it so that it blocks and acts as a synchronous call. It's extra work, but if you insist on synchronous behavior from something that is inherently asynchronous, it's your best solution.)

如果你需要同步行为,我会建议一个Windows钩子,让你的线程阻塞到正确的时间。 (换句话说,你可以使用异步方法然后将其包装起来,以便它阻塞并充当同步调用。这是额外的工作,但如果你坚持同步行为来自本质上异步的东西,那么这是你最好的解决方案。)

#2


You shouldn't use SendMessage to simulate mouse clicks and key presses. Use SendInput instead.

您不应该使用SendMessage来模拟鼠标点击和按键。请改用SendInput。

#3


You can perfectly use SendMessage(), in particular for menus (see MSDN and Google Groups for code samples)
(and hooks have nothing to do here)

您可以完美地使用SendMessage(),特别是菜单(请参阅MSDN和Google Groups以获取代码示例)(并且钩子在此处无关)