问题
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:
- open program
- choose from a selection of 2 tabs: a. stats b. config(which contains the text boxes)
- fill in the 4 text boxes to desired values
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 ?
回答1:
So the problem is to get a handle of the specific control. You may use for example following ways for finding control's handle:
- 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.
来源:https://stackoverflow.com/questions/20664417/adding-text-to-another-programs-text-box-c