user3116155
user3116155

Reputation: 61

adding text to another programs text box c++

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 ?

Upvotes: 4

Views: 2168

Answers (1)

Renat
Renat

Reputation: 9002

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.

Upvotes: 5

Related Questions