Login
`
Templates, Tools and Utilities
|
||
Add a comment to an Icetips ArticlePlease add your comments to this article.
Please note that you must provide both a name and a valid email address in order
for us to publish your comment. Comments are moderated and are not visible until they have been approved. Spam is never approved!
Back to article list Search Articles Add Comment Printer friendly Direct link Par2: Check for multiple instances of a program 1998-04-22 -- Jeff Berlinghoff After Global INCLUDEs:
ERROR_ALREADY_EXISTS EQUATE(183)
SECURITY_ATTRIBUTES GROUP,TYPE
nLength ULONG
lpSecurityDescriptor ULONG
bInheritHandle BOOL
END
Inside the Global Map:
MODULE('Kernal32')
CreateSemaphore(<*SECURITY_ATTRIBUTES lpSemaphoreAttributes>, LONG
lInitialCount, LONG lMaximumCount, *CSTRING lpName),LONG,RAW,PASCAL,NAME('CreateSemaphoreA')
CloseHandle(LONG hObject),BOOL,PASCAL
GetLastError(),ULONG,PASCAL
FindWindow(<*CSTRING lpClassName>, *CSTRING lpWindowName),UNSIGNED,PASCAL,RAW,NAME('FindWindowA')
SetWindowText(UNSIGNED,*CSTRING),PASCAL,RAW,NAME('SetWindowTextA')
IsIconic(UNSIGNED),BOOL,PASCAL
ShowWindow(UNSIGNED, SIGNED nCmdShow),BOOL,PASCAL
SetForegroundWindow(UNSIGNED),BOOL,PASCAL
END
On your FRAME, After Opening the Window:
IF ~StartNewAppInstance(0{prop:text}) THEN RETURN.
Create New Procedure named StartNewAppInstance
Prototype: (STRING),SHORT
Parameters: (WndTitle)
Data Section:
RetVal SHORT(True)
cTitle CSTRING(255)
cTemp CSTRING(255)
SemName CSTRING(255)
hSem LONG
hMe LONG
Processed Code:
SemName = 'Semaphore Name'
cTitle = WndTitle
hSem = CreateSemaphore(, 0, 1, SemName)
IF hSem AND (GetLastError() = ERROR_ALREADY_EXISTS)
n#=CloseHandle(hSem)
hMe = FindWindow(, cTitle) !rename new instance so we can find another
cTemp='Terminating Duplicate Instance'; SetWindowText(hMe, cTemp)
hMe = FindWindow(, cTitle)
IF hMe
IF IsIconic(hMe) THEN n#=ShowWindow(hMe, 1) ELSE n#=SetForegroundWindow(hMe).
RetVal=False !Cannot start a new instance, use already running instance
END
END
Today is November 23, 2024, 3:30 am This article has been viewed 35188 times.
|
|