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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a program from a VB app and keep the handle?

Status
Not open for further replies.

Paco75

Programmer
Oct 11, 2001
239
US
Hi I want to launch an existing application from my VB application... like notepad or any other existing on my pc and keep the handle for later API purpose... how can i do that? For a known application I use FindWindow but I need the Caption of this window... and since I don't know it...

thanks
 

Check into the ShellExecuteEx API. When you shell/launch another program this API will return a handle to the window to you.

Good Luck

 
Er...are you quite, quite sure about this? I think that you may find that the hWnd element of the SHELLEXECUTEINFO structure isn't quite what you think it is...

The following thread contains an alternative solution: thread222-153621
 

Well it's been awhile since I used it last but I used it in a program that shelled out another program and then I waited on it to close but from looking at the documentation you are so right (once again) thanks for catching that. I'll have to look at that program again and see how I do it...

There are many examples on this site. Search for "shell and wait" and you will come up with many hits.


 
You should use CreateProcess to start the application.
This will return you some information about the newly started process (thread handle and -id, process handle and -id).

There is a way to have your thread waiting until the new process has created its main window, but I do not remember how (check out the MSDN).

Use GetGUIThreadInfo (supply it the process id you obtained from CreateProcess) to obtain information about the newly created process (lots of window handles CAN be returned).

If you cannot find how to wait for the newly created process to have its main window created, you can always execute GetGUIThreadInfo in a loop until you receive a valid handle to the windows (or a timeout has occured).
 
In VB you have the "Shell" function which will return the ID of the process created by it. But you seem to want the handle. For details please check MSDN. Its have sample code to illustrate that function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top