` Check for multiple instances of a program using DDE (Richard Taylor ) - Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Icetips Article

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Par2: Check for multiple instances of a program using DDE
1999-10-04 -- Richard Taylor
 
32-bit programs, unlike 16-bit programs, do not automatically default to a single running instance. Users can easily initiate multiple program instances by just being a little impatient and double-clicking the program icon twice. For some applications this is not a problem, but for others it could be disastrous. Therefore, limiting Users to a single running instance is necessary and actually pretty simple to accomplish. The trick here is to make your program a DDE Server and have it look for an already running instance of itself before fully loading. You need to declare a global variable: Channel LONG And you need to prototype a Windows API call in the Inside the Global Map embed point: MODULE('Windows API Call') BringWindowToTop(LONG),BYTE,RAW,PASCAL,NAME('BringWindowToTop'),PROC END Then in the Program Setup embed point: Channel = DDECLIENT('MYPROGRAM') !look for running instances of this program IF Channel <> 0 ! and if found DDEEXECUTE(Channel,'INFRONT') ! tell the running instance to take focus DDECLOSE(Channel) RETURN ! then get out END Then in the AppFrame's ThisWindow.Init method, after opening window embed point: Channel = DDESERVER('MYPROGRAM') !set program as a DDE Server Then in the AppFrame's ThisWindow.TakeEvent method, top of CYCLE/BREAK support embed point: IF EVENT() = Event:DDEexecute IF DDEVALUE() = 'INFRONT' !tells it to bring itself to the front AppFrame{PROP:Iconize} = FALSE BringWindowToTop(AppFrame{PROP:Handle}) !and this does it END END


Today is April 19, 2024, 1:27 pm
This article has been viewed 35107 times.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: