透過CreateMutexA函式建立一個互斥體,然後用GetLastError來獲取返回值判斷是否重複開啟同一個應用。
外部函式宣告
Function ulong CreateMutexA (ulong lpMutexAttributes, int bInitialOwner, ref string lpName) library "kernel32.dll"
Function ulong GetLastError () library "kernel32.dll"
APP的open事件程式碼
string ls_mutex_name
long ll_mutex
long ll_err
if handle (GetApplication(),false) 0 then
ls_mutex_name = this.AppName
ll_mutex = CreateMutexA (0,0,ls_mutex_name)
ll_err = GetLastError ()
if ll_err = 183 then
messagebox("","程式重複開啟")
Halt close
end if
open(w_open)
透過CreateMutexA函式建立一個互斥體,然後用GetLastError來獲取返回值判斷是否重複開啟同一個應用。
外部函式宣告
Function ulong CreateMutexA (ulong lpMutexAttributes, int bInitialOwner, ref string lpName) library "kernel32.dll"
Function ulong GetLastError () library "kernel32.dll"
APP的open事件程式碼
string ls_mutex_name
long ll_mutex
long ll_err
if handle (GetApplication(),false) 0 then
ls_mutex_name = this.AppName
ll_mutex = CreateMutexA (0,0,ls_mutex_name)
ll_err = GetLastError ()
if ll_err = 183 then
messagebox("","程式重複開啟")
Halt close
end if
end if
open(w_open)