C++ code to open another already open program

I am currently working on a program that will take data from a txt file, and fill in some information in another program. My code reads the data in the correct format from the txt file however, i do not know how to tell my program to 'alt+tab' to another program that's already open in windows.
Thanks in Advance
Not sure if i understand you correctly, but it seems like you might not need two different programs to accomplish what you need.

If you really want to call one program from another then you can use the system command.
Hmmm, let me give an example. Let's say Internet Explorer is open and sitting down in the tray. I need to make my c++ program bring up Internet Explorer so it can enter data into a field (i.e. enter text into the search bar or address bar) In my case however the program isn't Internet Explorer it's a different program that has fields to put different data in. Also, I've tried looking into the system command and something called Create Process but i can't seem to do exactly what i need to do. The program i need to gain access too is already open, i need to bring it up and be able to enter text data into different fields.
Thanks for the help, greatly appreciated
I see your point. In that I suppose it would really help if you had the source of this second program, such that you could modify it by adding a mechanism to reload some ini file on file change or alternatively have a specific folder where such ini data time stamped updates are stored ad processed. The first program will be responsible for creating these ini updates for the second program to use.

Having a folder of multiple updates that are stored will provide a good solution for second program to process these updates in its own time, as opposed to these updates (on text fields of prgram2) being overwritten when 2nd program is not yet finished with current changeset.

This mechanism with some extra work could also be extended to utilised sockets as opposed to a file based system for transfer of updates.

The client (the 2nd program) will then have to buffer these updates so that it can process them in its own time.

If you don't have access to the source of the 2nd program then you might be able to use hooks from the 1st program to control 2nd. This solution may not be easy to implement as one cannot trully know the actual state of the 2nd program - ie it might be unsafe to hook into program2 and apply changes at certain times ...

Hope this helps.
Nah, actually you can achieve that with CreateProcess as you said. Just go get some informations about it.
Will CreateProcess still work for OP if the second program is already running?
It may or may not be practical to accomplish what you want. Can't really say if, or how without knowing the program you want to enter data into.
Some googling suggests you can use FindWindow() and SendInput()

Edit: Actually I think FindWindow + SendMessage works better.
#include <windows.h>

int main()
	HWND notepad = FindWindow(TEXT("Notepad"), NULL);
	HWND edit = FindWindowEx(notepad, NULL, TEXT("Edit"), NULL);
	SendMessage(edit, WM_SETTEXT, NULL, (LPARAM)TEXT("hello"));
	return 0;
Last edited on
FindWindow is Deprecated, isn't it? You should use EnumWindows.
Last edited on
Topic archived. No new replies allowed.