32位操作系统中,可以用两种方法实现:
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后才有效.
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器