0

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

000A0628 P WM_NCLBUTTONDOWN nHittest:HTMENU xPos:1706 yPos:395 [wParam:00000005 lParam:018B06AA 时间:27:23:56.156 点:(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

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

000A0628 P WM_NCLBUTTONDOWN nHittest:HTMENU xPos:1700 yPos:400 [wParam:00000005 lParam:019006A4 时间:27:25:02.156 点:(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(菜单已关闭) 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

有谁知道如何让它正常工作?

干杯

罗斯

4

3 回答 3

1

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

于 2009-04-27T23:40:06.677 回答
1

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

如果您需要同步行为,我建议您使用Windows 挂钩并让您的线程阻塞直到合适的时间。(换句话说,您可以使用异步方法,然后将其包装,使其阻塞并充当同步调用。这是额外的工作,但如果您坚持从本质上异步的事物中进行同步行为,那么这是您最好的解决方案。)

于 2009-04-28T00:01:41.430 回答
0

您可以完美地使用 SendMessage(),尤其是用于菜单(请参阅 MSDN 和 Google Groups 以获取代码示例)
(此处与钩子无关)

于 2009-04-28T12:57:02.033 回答