Page 1 of 1

How to close a previous instance?

Posted: Thu Jul 31, 2014 10:22 pm
by Manolo
Hi there!
I use this code to check if an instance is already open but, everytime I click on the program I get a warning about the opened instance but every new instance doesn`t close and it remains opened.

How Can I do to close every new instance?   :o

Many thanks!

`detects if a form is alread open, run it twice to see the effect

Declare findwindow as "FindWindowA" of "user32"
  Classname as string
  Windowname as string
  result as integer
end declare

object myform as form
  center
  caption="myform"
end object

detect

myform.showmodal

sub detect
  findwindow.classname="TForm1"
  findwindow.windowname="myform"
  findwindow.execute
  if findwindow.result>0 then
    showmessage "This window is already open"
  end if
end sub


How to close a previous instance?

Posted: Sat Aug 02, 2014 3:29 pm
by Marco
Something like this??

best regards


Declare findwindow as "FindWindowA" of "user32"
Classname as string
Windowname as string
result as integer
end declare

``=============added==============================
declare setfocus as "SetForegroundWindow" of user32
hwnd as integer
end declare
``================================================
object myform as form
center
caption="myform"
end object

detect

myform.showmodal

sub detect
findwindow.classname="TForm1"
findwindow.windowname="myform"
findwindow.execute
if findwindow.result>0 then
showmessage "This window is already open"
``==========added=============
setfocus.hwnd=findwindow.result
setfocus.execute
END
``============================
end if
end sub

How to close a previous instance?

Posted: Sat Aug 09, 2014 5:57 pm
by Manolo
Wow... Perfect!!!

Tnx a lot!!! :D

How to close a previous instance?

Posted: Sat Aug 27, 2016 7:26 am
by ClayAnderson2
thank you !

How to close a previous instance?

Posted: Tue Apr 04, 2017 6:20 am
by Maria
HAPPY TO READ

Re: How to close a previous instance?

Posted: Fri Sep 03, 2021 8:07 am
by beatrizkhole
Turns out the problem was the SetWinDelay instruction. From the docs: Although a delay of -1 (no delay at all) is allowed, it is recommended.In my case i am calling my applicaton.exe multiple times.I want to check whether another instance is running or not.Could not close the previous instance of this script. Keep Waiting? Hey all, I'm getting this error, and googling it seems to be of no help.