private sub form_load() If App.PrevInstance Then MsgBox "该程序已经运行!", vbInformation end End If end sub
二楼的代码可以写在Initialize事件中。
Private Sub Form_Load() If App.PrevInstance Then End End Sub
也可以用FindWindow和FindWindowEx找窗口,或者用DDE都行。 :)
既然是API组,当然要用API实现了 CreateMutex创建互斥量
sub main() if app.previnstance=true then msgbox "程序已经运行",vbexclamation+vbokcancel,"工程" else from1.show end sub
private sub form_load() If App.PrevInstance Then MsgBox "该程序已经运行!", vbInformation end End If end sub ====================================================== 不在一个目录也可吗?回答:不行。 还是: 看看goodname008(卢培培,充电中......) 的回复吧
If App.PrevInstance Then
MsgBox "该程序已经运行!", vbInformation
end
End If
end sub
If App.PrevInstance Then End
End Sub
CreateMutex创建互斥量
if app.previnstance=true then
msgbox "程序已经运行",vbexclamation+vbokcancel,"工程"
else
from1.show
end sub
If App.PrevInstance Then
MsgBox "该程序已经运行!", vbInformation
end
End If
end sub
======================================================
不在一个目录也可吗?回答:不行。
还是:
看看goodname008(卢培培,充电中......) 的回复吧
虽然 App.PrevInstance 可以屏蔽掉一般情况下的
但是将exe文件改个名字就不行了。还是通过注册表好。我觉得:)
2.if (findwindow(vbnullstring,"程序标题") then
end
else
me.caption="程序标题"
private sub form_load()
If App.PrevInstance Then end
end sub
就可以了
Dim ThWnd As Long
ThWnd = FindWindow(vbNullString, "form1")
If ThWnd <> 0 Then
MsgBox "已经运行了程序!", vbInformation, "提示信息"
Exit Sub
Else
Load form1
End If
Private Sub Form_Initialize()
If App.PrevInstance Then End
End Sub