PUBLIC gcOldDir,vcxname gcOldDir = SET('DEFAULT') + SYS(2003) SET DEFA TO "&gcOldDir" ****************************************************************************** &&获取程序运行名称 Declare INTEGER GetModuleHandle IN kernel32 INTEGER lpModuleName vcxid = ALLTRIM(STR(GetModuleHandle(0))) Declare INTEGER GetModuleFileName IN kernel32; INTEGER hModule,; STRING @ lpFilename,; INTEGER nSize lpFilename = SPACE(250) lnLen = GetModuleFileName (0, @lpFilename, Len(lpFilename)) vcxname = JUSTFNAME(ALLTRIM(Left (lpFilename, lnLen))) ****************************************************************************** #DEFINE ERROR_ALREADY_EXISTS 183 DECLARE INTEGER GetLastError IN WIN32API DECLARE INTEGER CreateMutex IN WIN32API INTEGER Security,SHORT Owned,STRING@ MutexName DECLARE SHORT CloseHandle IN WIN32API INTEGER PUBLIC hMutex, iResult, bCanRun hMetux=CreateMutex(0,0,vcxname) iResult=GetLastError() DO CASE CASE iResult==0 bCanRun=.T. CASE iResult==ERROR_ALREADY_EXISTS MessageBox("程序已经运行。"+SPACE(2),64,"提示") bCanRun=.F. OTHERWISE bCanRun=.F. MessageBox("GetLastError() returned "+ ltrim(str(iResult))) ENDCASE IF bCanRun ==.F. =CloseHandle(hMutex) * QUIT ENDIF
[此贴子已经被作者于2016-7-25 14:56编辑过]