Click Button and Read Text from Other Program on Windows

I have a protected application on windows, normally my clients have to run that program, click a button, copy some text from another text control, upload to somewhere…

I need to find a solution simulate button click and read the text control.

There are two buttons, generate and exit, and a text control.

Here is what I did in C++, build under Windows XP + Visual C++ 6.0/7.0 in CLI.

1 Run the program.

Sleep is required here, to ensure that you can find correct control.

2 Find controls

These CtrlID can be read by many *Spy app on windows.

3 Perform click and read from text control

In my case, Sleep is also required after BM_CLICK was sent to target program, otherwise I may have to click more than once.
So, I wrote a loop

I tried GetDlgItemText and GetWindowText, neither of these two works to get text from the control.
WM_GETTEXTLENGTH and then WM_GETTEXT is the best choice so far as I know.

4 Click Exit

Click Button and Read Text from Other Program on Windows by @sskaje: https://sskaje.me/2016/05/click-button-read-text-program-windows/