Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.141.44.9] |
|
Сообщ.
#1
,
|
|
|
Private Sub Form_Load() If App.PrevInstance Then End End Sub |
Сообщ.
#2
,
|
|
|
Есть еще вариант - создавать мутекс, главное правильно делать:
Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As SECURITY_ATTRIBUTES, ByVal bInitialOwner As Long, ByVal lpName As String) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal Handle As Long) As Long Private Const ERROR_ALREADY_EXISTS = 183& Private Type SECURITY_ATTRIBUTES nLength As Long lpSecurityDescriptor As Long bInheritHandle As Long End Type Dim hMutex As Long Private Sub Form_Load() Dim sa As SECURITY_ATTRIBUTES sa.bInheritHandle = 1 sa.lpSecurityDescriptor = 0 sa.nLength = Len(sa) hMutex = CreateMutex(sa, False, "hcs app.previnstance research") If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then MsgBox "Одна копия программы уже запущена! Данный экземпляр будет выгружен..." Unload Me End If End Sub Private Sub Form_Unload(Cancel As Integer) CloseHandle hMutex End Sub |