帮助单击窗口中的按钮 [英] Help clicking a button in a window

查看:68
本文介绍了帮助单击窗口中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要点击位于另一个窗口的按钮(以及其他窗口中的那个窗口)。



我几乎尝试过各种技术......使用LMBUTTONDOWN发送消息,使用WM_COMMAND发送消息,但没有任何效果。



我得到了一些delphi代码,它们执行相同的操作,对于同一个窗口,区别在于我需要用c ++来完成。



这是delphi代码:

 PostMessage (AHWND,WM_KEYDOWN,VK_RETURN,0); 
睡眠(10);
PostMessage(AHWND,WM_KEYUP,VK_RETURN,0);





AHWND是按钮的hwnd。该代码可以是复制粘贴到c ++,但是,它什么也做不了。



有些帮助吗?

解决方案

< blockquote>首先,让我告诉你,你可能正在尝试做一些肮脏的事情。编写UI模拟鼠标点击是件坏事。但是,我知道它可以合理地用于某些特殊目的:创建和播放鼠标/键盘宏,创建演示等。



你是什么试图做的不是普遍的而且不可靠的,它不能在所有情况下都起作用。模拟用户输入此方法的唯一正当方法:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx [ ^ ] 。



这是一个非常低级和通用的功能,它的工作方式与通过键盘或鼠标驱动程序完全相同。一直有效。



-SA


I need to click a button that is located in another window(and that window in some other process).

I tried pretty much every technique...Sending messages with LMBUTTONDOWN,sending messages with WM_COMMAND,but nothing worked.

I got my hands on some delphi code that does the same thing,for the same window,the difference is that I need to do it in c++.

This is the delphi code:

PostMessage(AHWND, WM_KEYDOWN, VK_RETURN, 0);
    Sleep(10);
    PostMessage(AHWND, WM_KEYUP, VK_RETURN, 0);



AHWND is the hwnd to the button.That code can be copy-pasted to c++,HOWEVER,it won''t do anything.

Some help?

解决方案

First of all, let me tell you that you are probably trying to do a dirty things. Writing UI simulation mouse clicks is bad thing. However, I understand that it might be reasonably used for some special purposes: creation and playing back mouse/keyboard macro, creation of the demonstrations, etc.

What you are trying to do is not universal and not reliable, it cannot work in all cases. The only decent way to simulate the user input it this method:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

This is a really low-level and universal function, it works exactly as it would do via a keyboard or a mouse driver. Always works.

—SA


这篇关于帮助单击窗口中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆