` Comment on an Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Add a comment to an Icetips Article

Please 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!

Your Name:  
Email:  
Header text/Subject:  

Please enter your comment in the box below:

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.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: