PB运行的程序只能运行一次

 

1.首先在global external functions声明外部函数如下:
  FUNCTION long FindWindowA( ulong Winhandle, string wintitle ) Library ″user32″
  然后在application的 Open 事件中加入如下代码:
  ulong l_handle, lu_class
  string ls_name
  ls_name = ″我的系统″ // 此处ls_name为系统主窗口的标题Title
  l_handle = FindWindowA(lu_class, ls_name)
  if l_handle > 0 then
  MessageBox(″提示信息″, ″应用程序″ + This.AppName + ″已经运行,不能多次启动!″)
  Halt Close
  else
  open(w_main) // 此处为系统主窗口
  end if
  这种方法是PowerBuilder联机帮助中的一个例子,是以系统主窗口的标题Title作为判别依据,若有其它与此Title同名应用程序在运行,再想启动此程序也会报应用程序已经运行。你可以将Title设为“计算器”,然后启动Windows附件中计算器程序,再运行你的PB应用程序试试。

 

2.声明外部函数:
  function ulong CreateMutexA (ulong lpMutexAttributes, int bInitialOwner, ref string lpName) library ″kernel32.dll″
  function ulong GetLastError () library ″kernel32.dll″
  然后在application的 Open 事件中加入如下代码:
  ulong ll_mutex, ll_err
  string ls_mutex_name
  if handle (GetApplication (), false) <> 0 then
  ls_mutex_name = this.AppName + char (0)
  ll_mutex = CreateMutexA (0, 0, ls_mutex_name)
  ll_err = GetLastError ()
  if ll_err = 183 then
  // 程序已经运行
  MessageBox (″提示信息″, ″程序已经运行了!″)
  Halt close
  else
  // 程序未运行
  open(w_main)
  end if
  else //开发模式
  open(w_main)
  end if
  这种方法必须在应用程序编译成可执行文件.exe后才有效。 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值