0
我正尝试使用SendMessage向Windows计算器发送一些简单的鼠标向下/向上消息。我可以通过直接将消息发送到按钮来按下按钮。但是,我无法成功将相同的消息发送到主计算器窗口句柄。鉴于hWnd是计算器的窗口句柄,这是我的代码。SendMessage WM_LBUTTONDOWN/UP在按钮上工作,但不是窗口
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,而不是fiveKey与x/y偏移更改为“5”键不起作用的位置
任何人都可以解释一下吗?我想最终使用此代码来模拟鼠标点击不具有计算器等按钮的不同应用程序。
好的,这是有道理的。我希望它能将消息传递给该地点的孩子,但如果不是的话,我将不得不寻找另一种方式来完成这项任务。 – 2010-08-09 20:14:42