将文本添加到另一个程序文本框C ++ [英] adding text to another programs text box c++
问题描述
我已经设法将文本发送到我使用c ++创建的自定义文本框,并发送到带有1个窗口和1个文本框的记事本,calc和其他程序.但是,我想将文本发送到另一个程序,该程序具有多个文本框,并且也位于选项卡中.它的结构如下:
i have already managed to send text to a custom text box i created using c++, and to notepad, calc and other programs all with 1 window and 1 text box. however, i want to send text to another program that has more than one text box and is in tabs too. it is structured like so:
- 打开程序
- 从2个选项卡中选择:统计b.config(包含文本框)
- 在4个文本框中填写所需的值
我没有运气就尝试过winspy ++,这是我一直在使用的简单代码.
i have tried winspy++ with no luck, here is simple code i have been working with.
#include <windows.h>
int main()
{
HWND hNote;
HWND hChild;
if (!(hNote=FindWindow("windowname",NULL)))
exit(1);
if (!(hChild=FindWindowEx(hNote,NULL,"EDIT",NULL)))
exit(2);
SendMessage(hChild,WM_SETTEXT,NULL,(LPARAM)"texttoadd");
return 0;
}
任何人都可以帮我解决这个问题吗?
Can anyone help me how can resolve this issue ?
推荐答案
所以问题是要获取特定控件的句柄.例如,您可以使用以下方法查找控件的句柄:
So the problem is to get a handle of the specific control. You may use for example following ways for finding control's handle:
- 可以通过控件ID来区分控件,然后使用 GetDlgItem 函数获取其句柄.可以使用Spy ++或InqSoft Windows Scanner等工具找到控件ID.
- MSDN表示,可以通过 ChildWindowFromPoint , ChildWindowFromPointEx 或 RealChildWindowFromPoint 函数.
- 或者可以通过 EnumChildWindows ,则可以使用自定义规则找到合适的一个.
- Control can be distinguished by control id, then use GetDlgItem function to get the its handle. Control id can be found using tools like Spy++ or InqSoft Windows Scanner or other.
- MSDN says that control can be found by coordinates of the point within parent window by ChildWindowFromPoint , ChildWindowFromPointEx or RealChildWindowFromPoint function.
- Or all controls can be enumerated within parent window by EnumChildWindows and an appropriate one can be found using custom rules.
这篇关于将文本添加到另一个程序文本框C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!