BBC BASIC for Windows
« help with programming »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:54pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: help with programming  (Read 973 times)
dynamic35
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 34
xx Re: help with programming
« Reply #6 on: Feb 17th, 2010, 9:28pm »

I would like to know what is the way to kill extra instances of a program
Sometimes I see 2-20 copies of the very same program existing and only one is enough. This takes place some times when you base the calling control in timers like when you use a TIME$ command that works in second level and then - based on equivalence of your tag time with TIME$'s time , followed by sys ShellExecute", @hwnd%, the program... this sys ..fetches many copies of the program into memory in one second slot
Rgs N62E25
Ps this happens while being ofcource in a loop and you may get rid of the problem by the WAIT 100 command after the sys call
for example
REPEAT
t$=MID$(TIME$,17,8)
IF t$="14:30:01" THEN SYS "ShellExecute", @hwnd%, 0, "Run1.exe", "", "C:\Program Files\runs", 1

REM WAIT 100 here helps to limit instances of program Run1.exe in 2

UNTIL INKEY(10)=0
« Last Edit: Feb 17th, 2010, 9:46pm by dynamic35 » User IP Logged

Richard Russell
Guest
xx Re: help with programming
« Reply #7 on: Feb 17th, 2010, 10:19pm »

on Feb 17th, 2010, 9:28pm, dynamic35 wrote:
I would like to know what is the way to kill extra instances of a program

Not exactly answering the question, but wouldn't it be easier to prevent the creation of multiple instances in the first place? Using a simple Boolean flag should easily achieve that (set the flag when TIME$ matches the specified time, reset it when it doesn't).

Again not answering the question, but if the program of which multiple instances are being created is one you have written yourself, you can prevent it using the code here:

http://bb4w.wikispaces.com/Detecting+a+second+instance+of+a+program

Although I can't help feeling that preventing multiple instances is the better way to proceed, terminating a program is often just a matter of posting it a WM_CLOSE message. Of course for that you must know its window handle, which could be a little tricky if there are several instances (SYS "FindWindow" only works safely if the window has a unique title).

Richard.
User IP Logged

dynamic35
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 34
xx Re: help with programming
« Reply #8 on: Feb 24th, 2010, 11:25pm »

Could you please give example of killing a program
among many programs coming in in sequency by TIME$
testing from day to day
I have a main process POX12 that calls various modules -say wall watch graphics=POX1 at 11:00 and at 15:00 and a measurement run with own graphics on screen, POX2 (hiding watch), at 11:15 and at 15:23

I want to kill Pox2 when POX 1 is active and I want to kill Pox1 when Pox2 is active

So I do not find anywhere what is the call kill pox1 and pox2 here like...
------------------------------
IF TIME$=m1$ THEN
SYS "ShellExecute", @hwnd%, 0, "pox1.exe", "", "C:\Program Files\poxes\"
****KILL here Pox2***
ENDIF

IF TIME$=m2$ THEN
SYS "ShellExecute", @hwnd%, 0, "pox2.exe", "", "C:\Program Files\poxes"
****KILL here Pox1****
ENDIF
User IP Logged

Malcolm
Guest
xx Re: help with programming
« Reply #9 on: Feb 27th, 2010, 2:41pm »

Have a look at :
http://bb4w.wikispaces.com/Listing+other+windows+and+applications

Presumably this could identify when the next program starts so you could close the current one. Be careful that they don't both commit suicide.
User IP Logged

dynamic35
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 34
xx Re: help with programming
« Reply #10 on: Feb 27th, 2010, 6:33pm »

Thank you Malcomm & Richard

So this seems to close A$ being a string found in among tittle bar of instance to be closed online.

INSTALL @lib$+"CALLBACK"

index% = 1
lParam% = 0
DIM hWnd%(1000)
SYS FN_syscalls("EnumWindows"), FN_callback(FNenumfunc(),2), lParam%
ret% = FN_sysresult
WM_CLOSE = &10
nMaxCount% = 255
DIM lpString% nMaxCount%, lpszFileName% nMaxCount%

PRINT "List of visible windows with Process ID and module name"
PRINT "=======================================================" '

FOR i% = 1 TO index%
$$lpszFileName% = ""
$$lpString% = ""
SYS "GetWindowText", hWnd%(i%), lpString%, nMaxCount%
SYS "IsWindowVisible", hWnd%(i%) TO vis%
SYS "GetWindowModuleFileName", hWnd%(i%), lpszFileName%, nMaxCount%
SYS "GetWindowThreadProcessId", hWnd%(i%), ^pid% TO tpid%
IF vis% AND $$lpString% <> "" THEN
COLOUR 0: PRINT "* " $$lpString%
COLOUR 1: PRINT " [pid=" + STR$(pid%) + "] ", $$lpszFileName%
REM 1 -------------Dynamic35 insert--------------
A$="ToBeClosed.exe"
IF INSTR($$lpString%,A$) THEN
SYS "SendMessage", hWnd%(i%), WM_CLOSE, 0, 0
ENDIF
REM 2
ENDIF
NEXT

END

DEF FNenumfunc(hwnd%, lparam%)
hWnd%(index%) = hwnd%
index% += 1
= 1
User IP Logged

Malcolm
Guest
xx Re: help with programming
« Reply #11 on: Feb 27th, 2010, 7:54pm »

You could probably achieve your aim with messaging.

I think you can broadcast a message with a custom message number. If the other program has a polling loop looking for messages you could operate that way. The two could have different messages so that you can control things.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls