View Full Version : Running Existence
Paul Fielder
02-17-2007, 09:53 PM
How do i check if my app is already running; and if so activate it before exiting?
kornalius
02-18-2007, 12:03 AM
You can check the with the Applications() function to return a list of all running PPL application handles running.
Then you can check each handle with AppName() to find out it's name.
If you want to check for a running Windows program, you can check the classname of a window or by caption using the FindWindow() function.
Paul Fielder
02-19-2007, 08:09 AM
OK, I got findWindow to discover if the app is running, with app$ = FindWindow(NULL, "PPC Euro");
but what is returned in app$.
I tryed KillApp(app$); but when the application is found I get PPL Runtime Error, Opcode KillAPP
Do I need to do anything in my other app to make it respond to an outside request to shutdown.
Any help greatfully recived.
PointOfLight
02-19-2007, 02:17 PM
KillApp is designed to work with another function from PPL called FindApp. These functions work on programs running as .PPL or .PPC files. I assume that you are trying to do this with both of your applications being executables, so you'll want to do the following:
app$ = FindWindow(NULL, "PPC Euro");
SendMessage(app$, WM_CLOSE, 0, 0);
kornalius
02-19-2007, 03:46 PM
Yes KillApp works only for internal running ppl programs within the same PPL.EXE session.
Paul Fielder
02-20-2007, 07:11 PM
I used:
app$ = FindWindow(NULL, "PPC Euro");
if(App$ <> NULL)
SendMessage(app$, WM_CLOSE, 0, 0);
end;
However as my orignal post I would have liked to have activated the orignal running app, and then close the newly started on.
I tried inserting SendMessage(app$, WM_ACTIVATE); but to no avail so now I close the old app with SendMessage(app$, WM_CLOSE, 0, 0); not the gold solution as I had wished but workable.
Many thanks for all your help, if you can provide advice, if it's possible to activate one application, and then close the calling one then I would be grateful.
PointOfLight
02-20-2007, 08:14 PM
Okay, here's what you can do:
local(active$, Low$, High$);
type(Low$, High$, TINT);
type(active$, TLONG);
Low$ = WA_ACTIVE;
High$ = 0;
active$ = MakeLong(Low$, High$);
app$ = FindWindow(NULL, "TitleOfOldApp");
SendMessage(app$, WM_ACTIVATE, active$, null);
curapp$ = FindWindow(NULL, "TitleOfNewApp");
PostMessage(curapp$, WM_CLOSE, 0, 0);
Teknoshock
04-18-2007, 06:12 PM
What would I do if both apps are the same? In other words, I have a program that i have setup a notification event for. This causes it to automagically run each time I turn my PPC on. If that program was already running when I turned the PPC off, turning the PPC on causes it to run again and produces lots of errors. Since the app is the same and I don't really care whether the old instance or the new instance is the one that remains running, could I just do:
app$ = FindWindow(NULL, "MyAppName");
if(App$ <;> NULL)
SendMessage(app$, WM_CLOSE, 0, 0);
end;
This, as I understand it, would kill the first instance of the program, then allow the second instance to continue running. Now, I assume I put this at the beginning of all my code so that it kills the first instance before attempting to do anything else. Is all this correct?
PointOfLight
04-18-2007, 08:10 PM
As long as you drop that code in before your application does any form creation, you should be just fine, and as you said, that should close the old instance and allow the new instance to run.
quangdx
04-19-2007, 12:44 PM
Okay, here's what you can do:
local(active$, Low$, High$);
type(Low$, High$, TINT);
type(active$, TLONG);
Low$ = WA_ACTIVE;
High$ = 0;
active$ = MakeLong(Low$, High$);
app$ = FindWindow(NULL, "TitleOfOldApp");
SendMessage(app$, WM_ACTIVATE, active$, null);
curapp$ = FindWindow(NULL, "TitleOfNewApp");
PostMessage(curapp$, WM_CLOSE, 0, 0);
Using this bit of code right at the beginning of my WinMain, i get the first instance closing and the second instance running.
I think cos i've yet to setup the second form, and both the old app and new app will have the same name.
what i ended up doing is, depending on if the app is already running, i would create the new form to have the name KillMe and then close it. otherwise, create the new form to have the proper game name.
local(active$, Low$, High$);
type(Low$, High$, TINT);
type(active$, TLONG);
Low$ = WA_ACTIVE;
High$ = 0;
active$ = MakeLong(Low$, High$);
app$ = FindWindow(NULL, "GameName");
if(app$)
h$ = newform( { KillMe} , { GAPIClass}, &mainproc);
SendMessage(app$, WM_ACTIVATE, active$, null);
curapp$ = FindWindow(NULL, "KillMe");
PostMessage(curapp$, WM_CLOSE, 0, 0);
else
h$ = newform({GameName}, {GAPIClass}, &mainproc);
ShowWindow(h$, SW_SHOW);
end;
it seems things in curly brackets don't show up on code sections of forum posts.
the first
h$ = newform( , , &mainproc);
should be
h$ = newform( { KillMe} , { GAPIClass}, &mainproc);
with KillMe in curly brackets for the first parameter and GAPIClass in curly brackets for the second parameter.
and the second
h$ = newform( , , &mainproc);
should be
h$ = newform( { GameName} , { GAPIClass}, &mainproc);
with GameName in curly brackets for the first parameter and GAPIClass in curly brackets for the second parameter.
PointOfLight
04-19-2007, 04:12 PM
Actually, I don't think you should have to go through quite so much trouble. Modify your WinMain code to do this:
local(active$, Low$, High$);
type(Low$, High$, TINT);
type(active$, TLONG);
Low$ = WA_ACTIVE;
High$ = 0;
active$ = MakeLong(Low$, High$);
app$ = FindWindow(NULL, "GameName");
if(app$)
SendMessage(app$, WM_ACTIVATE, active$, null);
return(false);
end;
//Now do your window creation code
As long as you execute the search code before the window creation code, it should not be possible for your application to find the current instance of itself. FindWindow will not return any application that hasn't created at least one window.
Teknoshock
04-19-2007, 08:50 PM
I have re-attached the file below...
Teknoshock
04-19-2007, 08:52 PM
I have attached my full code, which I am compiling to an .exe in PPL 1.25. The problem I am seeing is that when I set up a notification event to run the program when the PPC wakes up, it will get errors. I have setup the code that should tell it to not run a second instance of itself. If I don't setup the notification event, I get no errors, so it seems that something goes wrong when the notification event tries to start the program a second time.[br]1177015978_363_FT3682_slide1.9b.zip
quangdx
04-19-2007, 09:19 PM
that works great eric. i'm still very new to all this windows programming. so i did the best with my knowledge, but looking at your code, it makes perfect sense and yes makes my solution look incredibly long winded.
only thing is now, how to bring that first instance to the foreground, in windowsXP, it activates it, but any other open windows still cover the first instance.
zehlein
04-19-2007, 09:45 PM
so it seems that something goes wrong when the notification event tries to start the program a second time.[br]1177015978_363_FT3682_slide1.9b.zip
Are you sure you renamed your exe to "slide.exe" ?
Teknoshock
04-19-2007, 09:54 PM
yes, I am sure. After it compiles, I copy it into the directory that contains the GFX folder and the slide.ini file. I then rename it to slide.exe. I run the program. Next, I shut off the PPC. Wait 30 seconds, turn the PPC back on. Sometimes I get the error then, sometimes it doesn't occur until I repeat the process.
zehlein
04-19-2007, 10:07 PM
And what kind of errrors do you get?
Teknoshock
04-19-2007, 10:18 PM
I have attached the updated code (the last one, I discovered, was an older version... sorry about that) as well as the actual compiled program with all of it's necessary components (.ini, graphics, etc.) I also included 2 screenshots (ss1.jpg and ss2.jpg) of the errors. The second error repeats continuously until I soft reset.[br]1177021096_363_FT3682_slide1.8b.zip
Teknoshock
04-19-2007, 10:39 PM
I just discovered that this problem also occurs even without a notification event. Apparently the problem arises when turning the PPC on, even if it doesn't try to run a second time. I was wrong. The code in this thread must work. Something else in my program is failing, and if someone could give me an idea where, great, but if not, I'll dig into it and figure it out.
PointOfLight
04-19-2007, 10:52 PM
@quangdx: add this line of code after activating your app:
SetWindowPos(app$, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
@Teknoshock: I will try to take a look at it tonight if you've gotten no other response by the time I get to my computer at home.
Teknoshock
04-19-2007, 11:38 PM
The guys on this forum are the best. Thanks for your help guys.
Teknoshock
04-20-2007, 12:04 AM
I think I got it! Made some changes and now I'm not getting errors. I'll push it out to some friends to test, but I think I'm OK now. Thanks for everything guys.
PointOfLight
04-20-2007, 01:30 AM
Hopefully you've got that one nailed! Please let us know the results. I just got to my machine, so it probably would have been a bit before I could have looked at it anyway.
jackbnymbl
04-24-2007, 02:38 PM
Is this feature going to make it into A_C's slide.exe app?
I hope so, if it's going to be used in the same manner (which was my intention, if I can just figure out how to access the notification database... I tried doing it with the sktools demo, but I think I got errors.)
Is this feature going to make it into A_C's slide.exe app?
It's already there since v1.03.
jackbnymbl
04-24-2007, 06:01 PM
ok, tnx
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.