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

Shell Function

Status
Not open for further replies.

DF

Programmer
Mar 19, 1999
11
0
0
US
I want to start another program with my VB app and I want the file to be minimized with no focus. <br>
<br>
I am using the following code:<br>
Dim retval<br>
retval = shell(&quot;C:\windows\calc.exe&quot;,vbminimizednofocus)<br>
<br>
This executes the windows calculator but it remains on top of my form as my vbapp continues to run. Is there a way to minimize the file?<br>
Also, I would like to know if the program is already running before my app starts so I don't open a 2'nd copy of it. Can this be done?<br>
<br>
Thanks in advance,<br>
<br>
DF
 
Hi DF!<br>
<br>
See my reply to Dingle75, but in short, call the Win32 api function &quot;ShellExecute&quot;, which has an option for your program to wait until the other program finishes.<br>
<br>
Chip H.<br>

 
Hi,<br>
<br>
I don't understand why the calculater shouldn't minimize (if that's what you are inferring) when its started. The code looks fine.<br>
<br>
To find out if the program is already running you can use the FindWindow API call. FindWindow will return the handle of the application if it finds it and zero if not. You can either pass the ClassID if you know it or the title bar caption in the window you are looking for.<br>
<br>
The following example passes the title bar caption:-<br>
<br>
Private Declare Function FindWindow Lib &quot;user32&quot; _<br>
Alias &quot;FindWindowA&quot; (ByVal lpClassName As String, _<br>
ByVal lpWindowName As String) As Long<br>
<br>
Dim retval<br>
<br>
If FindWindow(vbNullString, &quot;Calculator&quot;) = 0 Then<br>
retval = Shell(&quot;calc.exe&quot;, vbMinimizedNoFocus)<br>
End If<br>
<br>
Hope this helps.<br>
<br>
Gaz.
 
try this...

Dim retval as long
retval = shell(&quot;C:\windows\calc.exe&quot;,0)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top