|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Shell works differently in two different programsanother program: Call Shell(PathName$, vbNormalFocus) where PathName$ is something like "C:\SomeFolder\SecondProgramName.exe" This works exactly as intended: if the Second Program is not running, it starts up; if it is already running, it's brought to the foreground. Now the problem: I use this exact same statement in another program to start/show a different Second Program and, while it starts a new instance of the second program all right, it will NOT bring an already-running instance to the foreground. Both of these situations are on the SAME computer (Windows XP, SP2). One works - one doesn't. I can go back and forth between them - one works, the other one doesn't. It doesn't matter whether I'm in the IDE or running the compiled versions - one works, the other doesn't. Can anyone give me some idea of what I might look for here? Any thoughts at all? Thanks "Martin" <martinval***@comcast.net> wrote in message bringing an already running instance to the front is being done by thenews:fh29j1hmd6u95vsauke1mt0qtj9mendujg@4ax.com > I'm using the following statement in a VB6 program to start/show > another program: > > Call Shell(PathName$, vbNormalFocus) > > where PathName$ is something like > "C:\SomeFolder\SecondProgramName.exe" > > This works exactly as intended: if the Second Program is not running, > it starts up; if it is already running, it's brought to the > foreground. application that you started. Shell does not do that. > Now the problem: I use this exact same statement in another program to That's pretty normal. Many apps do not handle the situation.> start/show a different Second Program and, while it starts a new > instance of the second program all right, it will NOT bring an > already-running instance to the foreground. > Both of these situations are on the SAME computer (Windows XP, SP2). If you want to do this for a specific application then there are ways to try> One works - one doesn't. I can go back and forth between them - one > works, the other one doesn't. It doesn't matter whether I'm in the IDE > or running the compiled versions - one works, the other doesn't. > > Can anyone give me some idea of what I might look for here? and find a running instance and bring it to the front but the best way to do that may depend on the specific app. If you want to do this in general then you are probably out of luck. -- Reply to the group so all can participate VB.Net: "Fool me once..."
Show quote
Hide quote
"Martin" <martinval***@comcast.net> wrote in message This has NOTHING to do with the Shell function (or any other means of news:fh29j1hmd6u95vsauke1mt0qtj9mendujg@4ax.com... > I'm using the following statement in a VB6 program to start/show > another program: > > Call Shell(PathName$, vbNormalFocus) > > where PathName$ is something like > "C:\SomeFolder\SecondProgramName.exe" > > This works exactly as intended: if the Second Program is not running, > it starts up; if it is already running, it's brought to the > foreground. > > Now the problem: I use this exact same statement in another program to > start/show a different Second Program and, while it starts a new > instance of the second program all right, it will NOT bring an > already-running instance to the foreground. > > Both of these situations are on the SAME computer (Windows XP, SP2). > One works - one doesn't. I can go back and forth between them - one > works, the other one doesn't. It doesn't matter whether I'm in the IDE > or running the compiled versions - one works, the other doesn't. > > Can anyone give me some idea of what I might look for here? > > Any thoughts at all? running a program, for that matter). It has EVERYTHING to do with how each app was written (IMO, you kind of confused things by referring to both apps you're shelling to as the "second app" <g> ). IOW, the first app you're shelling to was specifically written to bring a previous instance of itself to the foreground if run again. The second was not written to do this. With that said, about the only thing you can do is check yourself if this second program is already running and, if it is, bring it to the foreground; otherwise, launch it with Shell. -- Mike Microsoft MVP Visual Basic >This has NOTHING to do with the Shell function (or any other means of Sorry I didn't make myself clear. All four of the programs involved>running a program, for that matter). It has EVERYTHING to do with how each >app was written (IMO, you kind of confused things by referring to both apps >you're shelling to as the "second app" <g> ). IOW, the first app you're >shelling to was specifically written to bring a previous instance of itself >to the foreground if run again. The second was not written to do this. > >With that said, about the only thing you can do is check yourself if this >second program is already running and, if it is, bring it to the foreground; >otherwise, launch it with Shell. are mine - all written in VB6. Program "A" has a button on it that enables the user to start/show program "B". Program "C" (which is a modified version of "A") has a button on it that enables the user to start/show program "D" (which is a modified version of "B"). In any case, you and Bob have answered my question. The problem is in the program being started ("B" and "D"). I have looked in to it but I haven't figured it out yet. I do have a bunch of code that executes in the program's main form Resize event that should display the form. But for some reason, it works in "B" but not in "D". Thanks for the responses. Martin wrote:
Show quoteHide quote > [B]I'm using the following statement in a VB6 program to start/show > another program: > > Call Shell(PathName$, vbNormalFocus) > > where PathName$ is something like > "C:\SomeFolder\SecondProgramName.exe" > > This works exactly as intended: if the Second Program is not > running, > it starts up; if it is already running, it's brought to the > foreground. > > Now the problem: I use this exact same statement in another program > to............ > > These Guys are right about the shell but this may help you with your > question. > > This is a little different from your situation because I am only > running one executible. I was simply checking to see if that ONE > program was already running and if so - to bring it back to the > foreground if someone tried to start the program again. > > So I: > > Set a variable to hold the last app.title. If the program is already > running I use sendkeys to restore it to my foreground. > > Private Sub Form_Load() > Dim SaveTitle As String > If App.PrevInstance Then > SaveTitle = App.Title > MsgBox "The program is already running!" > AppActivate SaveTitle > SendKeys "% R", False > SendKeys "% ESC", False > End > End If > End Sub > > Works Great for my situation! > > I got this idea from 'support.microsoft.com/kb/142937/' > (http://support.microsoft.com/kb/142937/) I modified to work for my > situation so perhaps you can do the same. > > At least I hope that this helps someone out there. I spent a couple > of hours hunting this info down. There are a LOT of people out there > doing this same thing the hard way. > > Below is a URL with some code for your exact scenario (personally I > would try to trick it out with above code first) > > 'Using the RestoreHwnd method - egads man!' > (http://tinyurl.com/okc7y) > > > Later all... -- mjames727 ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------ |
|||||||||||||||||||||||