I am launching an external application from my program. If an instance of that application is still running, I want to bring it to the top instead of launching a new instance of that same process.
I call CreateProcess and receive a PROCESS_INFORMATION structure back. This gives me a process ID, a process handle, a thread ID, and a thread handle. The only other information I have about the external app is its path and file name.
My plan is this: I want to go from the process/thread information to the (HWND) handle to the external application's main window. From there, I want to get the window's title and store it in a static variable. Then on subsequent attempts to launch this external application, I will first try a FindWindow(sWindowTitle) and if that succeeds, I'll SetForegroundWindow on it, otherwise, I'll launch the process again.
The problem is, I can't find a way to get the main window handle from only process and thread IDs and handles.
Does anyone know a good way to do this?