LOCAL lhWnd,lhMutex,lcMutexName,llFound,llQuit llFound=.f. * Declare some API functions DECLARE Integer GetWindow in win32api Integer,Integer DECLARE Integer ShowWindow in win32api Integer,Integer DECLARE Integer GetDesktopWindow in win32api DECLARE Integer SetForegroundWindow in win32api Integer DECLARE Integer GetForegroundWindow in win32api DECLARE Integer CreateMutex in win32api Integer,Integer,String @ DECLARE Integer CloseHandle in win32api Integer DECLARE Integer GetLastError in win32api DECLARE Integer SetProp in win32api Integer,String @,Integer DECLARE Integer GetProp in win32api Integer,String @ DECLARE Integer RemoveProp in win32api Integer,String @ DECLARE Integer IsIconic in win32api Integer * Define the Mutex lcMutexName=const_APPLICATIONNAME+CHR(0) lhMutex=CreateMutex(0,1,@lcMutexName) if GetLastError()=183 * Mutex Already Exist - locate the original application lhWnd=GetDesktopWindow() && handle to the desktop lhWnd=GetWindow(lhWnd,5) && get the first child of the desktop do while lhWnd>0 and !llFound && loop until we find the window or run out of windows if GetProp(lhWnd,@lcMutexName)==1 if IsIconic(lhWnd)>0 ShowWindow(lhWnd,9) endif SetForegroundWindow(lhWnd) llFound=.T. endif lhWnd=GetWindow(lhWnd,2) && get handle to the next child of the desktop enddo CloseHandle(lhMutex) llQuit=.T. else * this assumes our application window is currently active lhWnd=GetForegroundWindow() * To help identify the application window we are adding * a property to it - which we can later search for SetProp(lhWnd,@lcMutexName,1) llQuit=.F. endifArnon