PB中如何控制应用程序启动后,不能在启动该应用程序?

pppcool 2002-07-17 11:49:07
PB中如何控制应用程序启动后,不能在启动该应用程序?
...全文
194 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
super_jack 2002-07-17
  • 打赏
  • 举报
回复
定义一个API:
FUNCTION uint FindWindowA (long classname, &

string windowname) LIBRARY "user32.dll"

在应用的open事件中:

uint val

val = FindWindowA(0, "你的程序的TITLE")

IF val > 0 THEN
MessageBox("程序已经运行", &
"MyApp is already running. You cannot &
start it again")
HALT CLOSE

ELSE
open(w_main)

END IF
super_jack 2002-07-17
  • 打赏
  • 举报
回复
定义一个API:
FUNCTION uint FindWindowA (long classname, &

string windowname) LIBRARY "user32.dll"

在应用的open事件中:

uint val

val = FindWindowA(0, "你的程序的TITLE")

IF val > 0 THEN
MessageBox("程序已经运行", &
"MyApp is already running. You cannot &
start it again")
HALT CLOSE

ELSE
open(w_main)

END IF
bluewindw 2002-07-17
  • 打赏
  • 举报
回复
用Findwindow API函数很简单的。

WorldMobile 2002-07-17
  • 打赏
  • 举报
回复
转贴FAQ上的
WorldMobile 2002-07-17
  • 打赏
  • 举报
回复
如何让pb程序只运行一次?
---------------------------------------------------------------

写一个ini文件,先将某个值定为0,程序运行判断其值,如果为1 不能再运行。第一次程序运行退出前将其值置为1
---------------------------------------------------------------

FUNCTION uint FindWindowA (long classname, string windowname) LIBRARY "user32.dll "

if findwindowa(0, "你系统的名字 ") > 0 then
messagebox( "应用正在运行 ", "XXXXXXX正在运行,您不能再次启动! ")
halt close
end if
---------------------------------------------------------------

老兄,一个还不够吗?
---------------------------------------------------------------

可以参考下面的资料,可能对你有帮助啊

1. 创建一个非可视化用户对象n_cst_win32sdk,该对象有以下的局部函数与外函数:

外部函数:
FUNCTION boolean ShowWindow( ulong winhandle,& int wincommand ) Library "user32 " FUNCTION boolean BringWindowToTop( ulong HWND )& Library "user32 " FUNCTION long FindWindowA( ulong Winhandle, & string wintitle ) Library "user32 "

局部函数 :
Of_FindWindowByTitle( string as_wintitle ) Return FindWindowA( 0, as_wintitle ) Of_ShowWindow( unsignedlong al_winhandle ) Return ShowWindow( al_winhandle, 5 ) Of_BringToTop( unsignedlong al_winhandle ) Return BringWindowToTop( al_winhandle )

2. 创建一个带有close按钮的测试窗口w_tes,窗口标题为First Window

3. 在应用程序的Open事件中增加如下代码:

n_cst_win32sdk lnv_sdk
long ll_winhandle

If Not IsValid( lnv_sdk ) Then
lnv_sdk = Create n_cst_win32sdk
End if
ll_winhandle = &
lnv_sdk.of_FindWindowByTitle( "First Window " )
If ll_winhandle > 0 Then
lnv_sdk.of_BringToTop( ll_winhandle )
lnv_sdk.of_ShowWindow( ll_winhandle )
destroy lnv_sdk
Return
End If
Open( w_sdktest )
nbgyf 2002-07-17
  • 打赏
  • 举报
回复
EnumWindowStationProc等API函数,
去VC论坛有限制程序只运行一次的讨论

Good Luck!
TangMingTM 2002-07-17
  • 打赏
  • 举报
回复
hzhxxx(hzhxxx)的方法最科学,我们目前也使用这种方法。
使用FindWindow偶尔有缺陷,当你连续双击桌面图标时,仍有可能被多次启动
hzhxxx 2002-07-17
  • 打赏
  • 举报
回复
private :

Function ULong CreateMutexA(ULong lpsa, Boolean fInitialOwner, String lpszMutexName) Library 'kernel32.dll'
Function uint GetModuleFileNameA(ulong hModule,ref string lpFilename,ulong nSize) Library "kernel32.dll"
//³ö´í API
Function Long GetLastError() Library 'kernel32.dll'



//*******************************************************//
// function : ÅжϳÌÐòÊÇ·ñÔËÐÐ
// parm : (none)
//return : true is running or false is not running
//auther : hzh
//date : 2002.04.29
//******************************************************//

string ls_AppName

application ga_app

ga_app = getapplication()

ls_AppName = ga_app.AppName

CreateMutexA(0,TRUE,ls_AppName)

IF GetLastError()=183 THEN RETURN TRUE

RETURN FALSE
hzhxxx 2002-07-17
  • 打赏
  • 举报
回复
private :

Function ULong CreateMutexA(ULong lpsa, Boolean fInitialOwner, String lpszMutexName) Library 'kernel32.dll'
Function uint GetModuleFileNameA(ulong hModule,ref string lpFilename,ulong nSize) Library "kernel32.dll"
//出错 API
Function Long GetLastError() Library 'kernel32.dll'



//*******************************************************//
// function : 判断程序是否运行
// parm : (none)
//return : true is running or false is not running
//auther : hzh
//date : 2002.04.29
//******************************************************//

string ls_AppName

ls_AppName = ga_app.AppName

CreateMutexA(0,TRUE,ls_AppName)

IF GetLastError()=183 THEN RETURN TRUE

RETURN FALSE
hzhxxx 2002-07-17
  • 打赏
  • 举报
回复
Function ULong CreateMutexA(ULong lpsa, Boolean fInitialOwner, String lpszMutexName) Library 'kernel32.dll'
Function uint GetModuleFileNameA(ulong hModule,ref string lpFilename,ulong nSize) Library "kernel32.dll"



//³ö´í API
Function Long GetLastError() Library 'kernel32.dll'

//*******************************************************//
// function : ÅжϳÌÐòÊÇ·ñÔËÐÐ
// parm : (none)
//return : true is running or false is not running
//auther : hzh
//date : 2002.04.29
//******************************************************//

string ls_AppName

ls_AppName = ga_app.AppName

CreateMutexA(0,TRUE,ls_AppName)

IF GetLastError()=183 THEN RETURN TRUE

RETURN FALSE
xjbs 2002-07-17
  • 打赏
  • 举报
回复
xxx
xjbs 2002-07-17
  • 打赏
  • 举报
回复
xxx

1,109

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧