单击另一个应用程序中的按钮,模拟鼠标坐标?
我尝试使用以下命令单击按钮:
private const int BN_CLICK = 0xF5;
private const uint WM_LBUTTONDOWN = 0x0201;
private const uint WM_LBUTTONUP = 0x0202;
SendMessage(sendButton, BN_CLICK, IntPtr.Zero, IntPtr.Zero);
SendMessage(sendButton, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(sendButton, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
以上所有内容都无法单击按钮,所以我想知道我拥有的其他替代方案,或者是否可以从其处理程序获取按钮位置 X 和 Y< /强>?
建议、想法真的很好。
I have tried to click on the button using the follow:
private const int BN_CLICK = 0xF5;
private const uint WM_LBUTTONDOWN = 0x0201;
private const uint WM_LBUTTONUP = 0x0202;
SendMessage(sendButton, BN_CLICK, IntPtr.Zero, IntPtr.Zero);
SendMessage(sendButton, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(sendButton, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
All the above fail to click the button, so I was wondering about other alternatives I have or if it is possible to get the button location X and Y from it's handler ?
Suggestions, ideas would be really good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果按钮有热键(Alt+...),您可以使用发送有关按下键盘按键的消息:
这是一个 C++ 代码。但您可以将所有这些函数导入 C# 并使用它们。您所需要的一切:激活目标窗口并使用正确的键作为参数调用此函数。
如果您有按钮的句柄,则调用
GetWindowRect
。它将返回一个指向RECT
结构的指针,该结构接收窗口左上角和右下角的屏幕坐标。因此,无论主窗口大小如何,您都可以执行点击模拟。使用它:
If the button have hot-key (Alt+...), you can use sending message about pressing keyboard keys:
It's a C++ code. But you can import all that functions to C# and use them. All what you need: activate target window and call this function with correct key as parameter.
If you have handle of the button then call
GetWindowRect
. It will return a pointer to aRECT
structure that receives the screen coordinates of the upper-left and lower-right corners of the window. So you will be able to perform click emulation regardless main windows size.Using it:
经过使用 sendmessage 的多次测试后,我已经解决了尝试 PostMessage 的问题,它的工作就像一个魅力......
解决了我的问题并将其发送到后台。
After many tests using sendmessage I have resolved trying PostMessage which worked like a charm...
Resolved my problem and sends it on background.