Page 1 of 2
how to call killprogram()?
Posted: Fri Mar 31, 2006 8:36 pm
by Klonk
Hi,
I want to use the function killprogram.
In the help for PB4b8 it's the syntax shows:
What is the Parameter "Program". It is not the number given by runprogram (I tried this already)
Can anyone help me?
Posted: Fri Mar 31, 2006 8:43 pm
by Trond
Code: Select all
pid = RunProgram("calc.exe", "", "", #PB_Program_Open)
Delay(1000)
KillProgram(pid)
Posted: Fri Mar 31, 2006 9:16 pm
by Klonk
Thanks a lot, maybe this example should be mentioned in the help file????
Posted: Fri Mar 31, 2006 9:28 pm
by ts-soft
better close the program after kill
Code: Select all
pid = RunProgram("calc.exe", "", "", #PB_Program_Open)
Delay(1000)
KillProgram(pid)
CloseProgram(pid) ; clear Datas
Posted: Fri Mar 31, 2006 9:36 pm
by Klonk
Another question:
This is what I want to do:
My program calls another program, e.g. notepad.exe. When closing my program notepad should be closed also.
Killprogram would just kill notepad regardless whether the text has been changed and should be saved or not.
I want to send a message (or whatever) to notepad to achieve a proper close (Same effect as exiting notepad myself)
Any ideas how to achieve this?
Posted: Fri Mar 31, 2006 9:47 pm
by ts-soft
You can use the sendkeys Snippet from the CodeArchiv:
http://www.purearea.net/pb/CodeArchiv/I ... endKeys.pb
Posted: Fri Mar 31, 2006 9:55 pm
by Trond
And what to do if the user presses cancel? (Then notepad does not exit.)
Posted: Fri Mar 31, 2006 10:05 pm
by Klonk
Trond wrote:And what to do if the user presses cancel? (Then notepad does not exit.)
Well this is not that important to me because the user didn't wanted to save when cancelling, but at least he was asked to save...
Posted: Fri Mar 31, 2006 10:14 pm
by dracflamloc
Use SendMessage_(notehwnd,#WM_CLOSE) or something like that.
Posted: Fri Mar 31, 2006 10:34 pm
by ts-soft
Code: Select all
PostMessage_(FindWindow_(@"notepad", 0), #WM_CLOSE, 0, 0)
Posted: Fri Mar 31, 2006 10:41 pm
by Trond
Klonk wrote:Trond wrote:And what to do if the user presses cancel? (Then notepad does not exit.)
Well this is not that important to me because the user didn't wanted to save when cancelling, but at least he was asked to save...
If he doesn't want to save he clicks no. When he clicks cancel usually his changes are not lost, he can still save them after making additional changes.
Posted: Sun Apr 02, 2006 5:02 am
by PB
> You can use the sendkeys Snippet from the CodeArchiv:
>
http://www.purearea.net/pb/CodeArchiv/I ... endKeys.pb
That tip in the CodeArchiv is really old now, I have updated it a while back,
to include more keys and also to fix an incorrect value (304 should be 303):
http://www.purebasic.fr/english/viewtopic.php?t=3766
Also, it was NOT authored by Danilo as the CodeArchiv says, but by me!

Posted: Tue Apr 04, 2006 8:57 am
by Klonk
ts-soft wrote:Code: Select all
PostMessage_(FindWindow_(@"notepad", 0), #WM_CLOSE, 0, 0)
This looks good to me, except one thing: notepad was just an example. Is there a more flexible way? Maybe replacing FindWindow_(@"notepad", 0) with a command that uses the number delivered from runprogram??
Posted: Tue Apr 04, 2006 10:09 am
by Michael Vogel
ts-soft wrote:better close the program after kill
Code: Select all
pid = RunProgram("calc.exe", "", "", #PB_Program_Open)
Delay(1000)
KillProgram(pid)
CloseProgram(pid) ; clear Datas
Does something like CloseProgram exists also for threads? I need to unlock files, after having aborted a file copy process...
Code: Select all
Global dest.s="c:\test.xxx"
Procedure copy()
Debug DeleteFile(dest)
CopyFile("c:\windows\kalender.bmp",dest)
EndProcedure
Procedure backgroundcopy(dummy.l)
copy()
EndProcedure
id=CreateThread(@backgroundcopy(),0)
Delay(50)
KillThread(id)
;Something like CloseProgram(id)???
Delay(50)
Debug DeleteFile(dest)
Delay(2000)
Debug DeleteFile(dest)[/quote]
Posted: Tue Apr 04, 2006 1:00 pm
by PB
> Thanks a lot, maybe this example should be mentioned in the help file????
I don't understand... in one post you say it's NOT the number given by
RunProgram because you've tried it, but then you say the above when
an example is given where it IS the number given by RunProgram.
