【发布时间】:2010-08-10 03:35:14
【问题描述】:
我正在尝试使用 SendMessage 向 Windows Calculator 发送一些简单的鼠标向下/向上消息。我已经能够通过将消息直接发送到按钮来按下按钮。但是,我无法成功地将相同的消息发送到主计算器窗口句柄。鉴于 hWnd 是计算器的窗口句柄,这是我的代码。
IntPtr fiveKey = FindWindowEx(hWnd, IntPtr.Zero, "Button", "5");
int x = 5; // X coordinate of the click
int y = 5; // Y coordinate of the click
IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates
IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
const uint downCode = 0x201; // Left click down code
const uint upCode = 0x202; // Left click up code
SendMessage(fiveKey, downCode, wParam, lParam); // Mouse button down
SendMessage(fiveKey, upCode, wParam, lParam); // Mouse button up
谁能向我解释为什么将消息发送到 hWnd 而不是将 x/y 偏移量更改为“5”键位置的 FiveKey 不起作用?我希望最终使用此代码来模拟鼠标点击另一个没有计算器等按钮的应用程序。
【问题讨论】:
标签: windows mfc sendmessage