I am currently absolutely new to c++, i did a few tutorials but mostly have fun making random programs to make my life easier - so there is no rush or importance to answer this would just be nice =D
I am currently trying to launch a program then type into a textbox in that program. But when i use system("notepad.exe"); then use the commands to type into it, the program sticks on the notepad and does not continue with the rest of the script. The typing portion of my script works, but it wont go past the opening of the notepad no matter what i try.
The code won't continue until notepad.exe is closed.
Try: system("call notepad.exe");
When you do system calls, it's as if you were outside of the program and giving commands straight to the OS. Therefore, if you have questions regarding the system("") command, look up bat, cmd, or DOS commands in google for help.
Is there any way to set a focus of which window to type into? I am going to be launching 4 instances of a program at the same time but i want it to cycle through each of the 4 and input account information on each.
I would suggest using CreateProcess() to launch notepad, this will allow you to pass in a "STARTUPINFO" struct that will be filled in. Pass the lpTitle data in this struct to "FindWindow()" as the second argument and it will return a handle to window whose title matches that text.
I will look into that, in the end i need to go to each of 4 different programs and input passwords and account names for each, didn't think it would be THIS complicated but it makes it more fun this way.
I think I've found an even more reliable method, I haven't tested this yet but it looks promising. You would still use "CreateProcess()" but after the application has launched pass the 'hThread' HANDLE in the 'PROCESS_INFORMATION' struct to the "GetGUIThreadInfo()" function, this will fill in a 'GUITHREADINFO'1 struct which has a data member called 'hwndActive'. This is a handle to the active window in the thread which you can then pass to "SetFocus()". This works out better then the other suggestion I had because "FindWindow()" is less specific and will return a handle to any window whose title matches your input.
1: Don't forget to set the 'cbSize' data member to sizeof(GUITHREADINFO).