Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start an exe, then wait for its window, and get the top handle ....

Status
Not open for further replies.

zaphy2k2

Programmer
Dec 23, 2001
30
GB
Hi,

Im pretty new to C++, but have done alot with java/vb etc. I am tearing my hair out with this :

I am launching an App with CreateProcess(), and then need to get its HWND for the main window (eg notepad.exe) to set it to always stay on top. Now when i launch it, it may not have initialized the top window byt the time the C code executes. Can i either get it to post me a message when the window is ready, or get it some other way? I have been using getActiveWindow, but i dont always get it (sometimes i get the console / VC++ etc). I can then set it to alwaysOnTop with setWindowPos, and wait for it to end with CreateSingleObject(). Any help / further questions u want to ask me on the problem would be greatly appreciated.

Cheers

-=A=-
 
Hi, I've dabbled in some stuff that is very similar to what your trying to accomplish.

The CreateProcess() fxn has a return-type of BOOL so you can use that to determine when the code has finished executing and the process has been created.

I was stumped in my project when I could not find a way to return an HWND from the CreateProcess() fxn. But there are 2 structs associated with the CreateProcess() fxn that hold all of the attributes of the New Window. They are STARTUP_INFO and PROCESS_INFO structs, I believe the vars useful to you are in the PROCESS_INFO struct.

PROCESS_INFO records the ID and other 32-bit identifiers of the process and the thread that is created. Before you close both the process and the thread I believe it may be possible to use those ID's, either the thread ID or process ID to perform a getHWND() fxn before you close the thread and processes.

Example:
HWND m_hWnd;
m_hWnd = pi.hProcess.getHWND();


or something to that effect, not sure if that would work since I've been out of the VC++ loop for awhile. Probably someone could suggest a better code example and see if that works. Rocco is the BOY!!

M O T I V A T E!
 
To figure out when CreateProcess has finished creating the process, use WaitForInputIdle(handle of process). As soon as WaitForInputIdle returns, use GetForegroundWindow()to get an HWND for the process window.

Ulysses
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top