Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2004, 08:41 AM
Registered User
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Shell Process handling orFocus

Hi,
have the following code:
if Dir(App.Path & "\PPM.exe") = "" Then
      MsgBox ("Multi Currency functionality not available")
      Exit Sub
End If
Shell App.Path & "\PPM.exe", vbNormalFocus

Question:
How do I test whether the application PPM.EXE is running already and instead of starting a new instance of PPM.EXE rather set focus to the already running instance of PPM.EXE

 
Old May 4th, 2004, 04:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The following code will only work if PPM.EXE is shown in the task bar. You must also know what the caption of the taskbar button should be.
Code:
On Error Resume Next

AppActivate "PPM.EXE" ' This should be the caption of the application
' If the application is not running then a run-time
' error 5 will be generated. Test for this error now
If Err.Number = 5 Then
    If Dir(App.Path & "\PPM.exe") = "" Then
        MsgBox ("Multi Currency functionality not available")
        Exit Sub
    Else
        Shell App.Path & "\PPM.exe", vbNormalFocus
    End If
Else
    ' PPM.EXE was already running and now has the focus
End If
There are other ways of doing this with API calls, however this is the simplest. The problem with it is that it will not work if the caption of PPM.EXE changes during it's execution.

Regards
Owain Williams
 
Old May 4th, 2004, 04:38 AM
Registered User
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, works like a charm. Apart from the title of the application changing during the life of the Application, are there any other exceptions/issues one should be aware of?

 
Old May 4th, 2004, 05:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The only other issue I can think of will be if the app has been minimized, as far as I know there is no easy way to restore the app's window from another program if the app has been minimized.

Regards
Owain Williams





Similar Threads
Thread Thread Starter Forum Replies Last Post
process.startinfo opens new instance of process Anypond General .NET 0 August 28th, 2008 05:35 AM
How to: Shell???? Apocolypse2005 Visual Basic 2005 Basics 1 April 24th, 2008 06:31 AM
Shell seananderson Beginning VB 6 3 March 16th, 2007 05:41 AM
Handling User Action/intruptiong the process avbabu VS.NET 2002/2003 0 December 16th, 2004 08:41 AM
Shell programming programmed C++ Programming 1 November 30th, 2003 07:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.