Launching a program then typing to it.

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.
This sound like a Windows question. Can you please post it in the Windows Programming forum.
Here is how the system functions works:

Call a local shell.
Type in whatever you fed the system function (i.e. notepad.exe).
Waits for that to finish.
system function returns.

So if you're using the system function to open notepad, you need to close notepad for the program to continue running.

As an aside, C++ is not a scripting language. It is compiled. C++ programs are not called scripts. They are programs. The source code is called code, or source code.
Last edited on
Moschops wrote:
The source code is called code, or source code.

This made me chuckle.
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.
I am currently trying to launch a program then type into a textbox in that program.

What's meant to happen to the words you type in?
I am just trying to launch the notepad.exe then have it also type some words into it. I have the typing part down i just need some way to launch notepad without stopping the code.

the system("call notepad.exe"); also did not work =(
Last edited on
Use CreateProcess or ShellExecute(Ex) if you don't want to wait for external program to finish (this is the default behaviour anyway).

To "type into a texbox" you need to get a handle to that textbox window, then call SetWindowText or send WM_SETTEXT directly.
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 am not really understanding how to use that...i have a feeling if i posted my current code people will laugh at me but how do i use that to change focus exactly? use the application name or what?
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.
can one of you experts look at my question that's below this on the forum? thanks!
Last edited on
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).
Topic archived. No new replies allowed.