1.首先在global external functions声明外部如下:
FUNCTION long FindWindowA( ulong Winhandle, witle ) Library ″user32″
然后在application Open 事件中加入如下代码:
ulong l_handle, lu_
ls_name
ls_name = ″我系统″ // 此处ls_name为系统主窗口标题Title
l_handle = FindWindowA(lu_, ls_name)
l_handle > 0 then
MessageBox(″提示信息″, ″应用″ + This.AppName + ″已经运行,不能多次启动!″)
Halt Close
open(w_) // 此处为系统主窗口
end
这种思路方法是PowerBuilder联机帮助中个例子是以系统主窗口标题Title作为判别依据若有其它和此Title同名应用在运行再想启动此也会报应用已经运行你可以将Title设为“计算器”然后启动Windows附件中计算器再运行你PB应用试试
2.声明外部:
function ulong CreateMutexA (ulong lpMutexAttributes, bInitialOwner, ref lpName) library ″kernel32.dll″
function ulong GetLastError library ″kernel32.dll″
然后在application Open 事件中加入如下代码:
ulong ll_mutex, ll_err
ls_mutex_name
handle (GetApplication , false) <> 0 then
ls_mutex_name = this.AppName + char (0)
ll_mutex = CreateMutexA (0, 0, ls_mutex_name)
ll_err = GetLastError
ll_err = 183 then
// 已经运行
MessageBox (″提示信息″, ″已经运行了!″)
Halt close
// 未运行
open(w_)
end
//开发模式
open(w_)
end
这种思路方法必须在应用编译成可执行文件.exe后才有效.
最新评论