4

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 ?

Sitansu
  • 3,225
  • 8
  • 34
  • 61
  • 3
    Spy++ is exactly the tool that will help you find the child window hierarchy. Why did you have "no luck"? – Jonathan Potter Dec 18 '13 at 17:27
  • i made a mistake when reading the results from winspy, i made sure i had the correct handle by using wm_gettext. however, there is now another problem, the handle changes every time the program is closed and reopened. – user3116155 Dec 18 '13 at 20:47

1 Answers1

5

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.
Renat
  • 7,718
  • 2
  • 20
  • 34