|
Home Page |
About ToolBook |
ToolBook Tips |
ToolBook Projects |
ToolBook Links |
Guest Book |
How to run only one instance of program
Sometimes users click several times on the same icon and run several instances of program.
To prevent it you can create a global atom when starting your program if it does not exist yet.
(Global atoms are string variables for all Windows applications)
-- FirstIdle script for first page
to handle FirstIdle
system logical myFirstEnter
system int myAtom
linkdll "USER"
INT GlobalFindAtom(STRING)
INT GlobalAddAtom(STRING)
INT GlobalDeleteAtom(INT)
end
myText = "My program already here" -- Here might be any text - it is global string variable for all Windows applications
get GlobalFindAtom(myText)
if It <> 0 -- This global atom already exists
request "Another instance of this program already exists or this program was finished incorrectly." & CRLF & "Run this program again?" with "Yes" or "No"
if It = "No"
send Exit to this book
break to system
else
myFirstEnter = false
end if
else -- Create global atom
myAtom = GlobalAddAtom(myText)
myFirstEnter = true
end if
end
-- Exit script for book
to handle Exit
system int myAtom
system logical myFirstEnter
if myFirstEnter = true --This is a first instance
get GlobalDeleteAtom(myAtom)
end if
forward
end
|