how to call killprogram()?

Just starting out? Need help? Post your questions and find answers here.
Klonk
Enthusiast
Enthusiast
Posts: 173
Joined: Tue Jul 13, 2004 2:17 pm

how to call killprogram()?

Post by Klonk »

Hi,
I want to use the function killprogram.
In the help for PB4b8 it's the syntax shows:

Code: Select all

KillProgram(Program)
What is the Parameter "Program". It is not the number given by runprogram (I tried this already)

Can anyone help me?
Bye Karl
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Code: Select all

pid = RunProgram("calc.exe", "", "", #PB_Program_Open)
Delay(1000)
KillProgram(pid)
Klonk
Enthusiast
Enthusiast
Posts: 173
Joined: Tue Jul 13, 2004 2:17 pm

Post by Klonk »

Thanks a lot, maybe this example should be mentioned in the help file????
Bye Karl
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Klonk
Enthusiast
Enthusiast
Posts: 173
Joined: Tue Jul 13, 2004 2:17 pm

Post 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?
Bye Karl
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

You can use the sendkeys Snippet from the CodeArchiv:
http://www.purearea.net/pb/CodeArchiv/I ... endKeys.pb
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

And what to do if the user presses cancel? (Then notepad does not exit.)
Klonk
Enthusiast
Enthusiast
Posts: 173
Joined: Tue Jul 13, 2004 2:17 pm

Post 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...
Bye Karl
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Use SendMessage_(notehwnd,#WM_CLOSE) or something like that.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Code: Select all

PostMessage_(FindWindow_(@"notepad", 0), #WM_CLOSE, 0, 0)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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! :evil:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Klonk
Enthusiast
Enthusiast
Posts: 173
Joined: Tue Jul 13, 2004 2:17 pm

Post 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??
Bye Karl
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post 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]
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. :?:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply