为什么我的软件可以打开几个啊?
我编的软件生成EXE时候 为什么可以一直打开?我打开了一个,在点击这个EXE文件的时候还能打开,有什么办法可以解决吗?
可在你程序加入模快:
Option Explicit
Private Const ERROR_ALREADY_EXISTS = 183&
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As SECURITY_ATTRIBUTES, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
Private Sub Main()
Dim sa As SECURITY_ATTRIBUTES
sa.bInheritHandle = 1
sa.lpSecurityDescriptor = 0
sa.nLength = Len(sa)
Call CreateMutex(sa, 1, App.Title)
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
MsgBox "程序已经运行!"
End If
End Sub