发信人: hunter__fox(雁回西楼)
整理人: hunter__fox(2002-03-16 21:48:54), 站内信件
|
上一次,说到这一问题,我提出的解决办法是通过锁定本地表的方式来实现,现
在给出用API的解决办法。
此段代码可用在系统和程序中。
这是所用 WindowsAPI 的简介:
FindWindow :通过标题内容寻找窗口
GetClassNameA :通过对象句柄取得类名
FindWindowExA :通过窗口类名遍历窗口
GetWindowTextA :通过对象句柄取得对象标题
Declare Integer FindWindow IN USER32.DLL AS FindWindow ;
String,String
Declare Integer GetClassNameA In user32.Dll As GetClassName ;
Integer,String @,Integer @
Declare Integer FindWindowExA In user32.Dll As FindWindowEx ;
Integer,Integer,String,String
Declare Integer GetWindowTextA In user32.Dll As GetWindowText ;
Integer,String @,Integer @
Local hWnd,hWnd2
Local cClassName,nClassNameLen
Local cWndTst,nWndTstLen
&& 取得窗口类名
hWnd = FindWindow(0,_screen.Caption)
cClassName = Space(256)
nClassNameLen = GetClassName(hWnd,@cClassName,255)
cClassName = Left(cClassName,nClassNameLen)
Release nClassNameLen
&& 开始遍历窗口
hWnd2 = 0
Do While .T.
hWnd2 = FindWindowEx(0,hWnd2,cClassName,0)
cWndTst = Space(256)
nWndTstLen = GetWindowText(hWnd2,@ cWndTst,255)
If hWnd2 = 0 && 遍历完毕
Exit
EndIf
If nWndTstLen = 0 && 无标题窗口----一个VFP程序运行时,系统中有多个这样的窗口
Loop
EndIf
cWndTst = Left(cWndTst,nWndTstLen)
If Not hWnd = hWnd2 && 本程序的另外进程
MessageBox("程序已经运行,不能重复加载!")
Exit
EndIf
EndDo
Release hWnd,cClassName,cWndTst,nWndTstLen
---- 作者:hunter__fox【雁回西楼】
※ 来源: 网易虚拟社区 广州站.
※ 个人天地 流水情怀[ccbyy] 灌水精英 NO:003
※ 编程开发 VFP[VFP] |
|