CreateProcess of console app, and get the main window handled

553 views Asked by At

I am trying to write a program what will manage few console windows, my program will be able to CreateProcess() for new console windows, get a window main handle and the use that handle to resize, close, hide, change title etc. But I cannot find a reliable way to get a main window handle. The purpose is to have a tab bar and switch between created console windows with the click on the tab.

I have tried few ways:

1) use windows "cmd.exe" ability to set window title, and then FindWindow("tmp_title"...) This has a problem, I do not need cmd.exe running, and also I need a processID for the target program not the cmd.exe. Maybe I should use this way but check for children subprocesses?

2) EnumWindows() then CreateProcess() then wait 40 ms, then EnumWindows() again and find the new window. This is unreliable! I got two new windows sometimes for weird reasons.

3) use GetWindowThreadProcessId() + EnumWindows(). This worked the best on XP, but on win7 the found window seems to be the wrong one, it's GetWindowText() returns "DefaultIME" and hide/show of this window does nothing. So it is obviously a wrong one.

So any idea how to do it reliably and if possible cross-platform (Cross-windows, XP,Vista,7)

0

There are 0 answers