用户登陆 用户注册
您的位置:首页> 电脑专栏>内容正文
Powerbuilder中限制应用程序只运行一次
[正文]:可以用两种方法实现:     1.首先在global external functions声明外部函数如下:     function long findwindowa( ulong winhandle, string wintitle ) library ″user32.dll″     注:如果你使用的是pb10.0, 在该api函数后面就加一个alias for "findwindowa;ansi",否则会出现乱码    然后在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


网站首页 培训课程 维修指南
技术文章 家电专栏 供应信息
求购信息 培训资讯 展会信息
电脑专栏 教程下载 资料下载
常用软件 PLC教程 PLC资料
变频伺服 低压电器 维修资料
人机界面 自控仪表 工控机类
文章标题: 搜文章
中国工控资源网手机版 2012
电话:010-67577139 13811659603
培训咨询QQ:657167934 471895637 销售咨询QQ:623769457
联系邮箱:zggkzyw@163.com
 京ICP备11002135号
报时(2026-04-02 09:13:01) 流量统计