How to close a previous instance?

Here one can report bugs or hold discussions about bugs updates and work arounds.
Post Reply
Manolo
Posts: 16
Joined: Fri Jun 15, 2007 4:57 pm

How to close a previous instance?

Post: # 1197Post Manolo
Thu Jul 31, 2014 10:22 pm

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


Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

How to close a previous instance?

Post: # 1198Post Marco
Sat Aug 02, 2014 3:29 pm

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

Manolo
Posts: 16
Joined: Fri Jun 15, 2007 4:57 pm

How to close a previous instance?

Post: # 1199Post Manolo
Sat Aug 09, 2014 5:57 pm

Wow... Perfect!!!

Tnx a lot!!! :D

ClayAnderson2
Posts: 3
Joined: Sat Aug 27, 2016 7:16 am

How to close a previous instance?

Post: # 1200Post ClayAnderson2
Sat Aug 27, 2016 7:26 am

thank you !

Maria
Posts: 3
Joined: Tue Apr 04, 2017 6:15 am

How to close a previous instance?

Post: # 1201Post Maria
Tue Apr 04, 2017 6:20 am

HAPPY TO READ

beatrizkhole
Posts: 1
Joined: Fri Sep 03, 2021 8:01 am

Re: How to close a previous instance?

Post: # 98358Post beatrizkhole
Fri Sep 03, 2021 8:07 am

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.

Post Reply