adding text to another programs text box c++

旧城冷巷雨未停 提交于 2021-02-04 18:31:10

问题


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:

  1. open program
  2. choose from a selection of 2 tabs: a. stats b. config(which contains the text boxes)
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!