bueno suena simple pero no he podido dar con la solución a esto.. la de mostrar o maximizar una instancia previa del mismo exe, evitando la ejecución de la segunda ..
para evitar ejecución del mismo exe 2 veces uso la función api CreateMutex :
Option Explicit
'Code by Adam Verwijs
Const ERROR_ALREADY_EXISTS = 183&
Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As Any, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
Private Declare Function ReleaseMutex Lib "kernel32" (ByVal hMutex As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_NORMAL = 1
Dim ventana As Long
Private Sub Form_Load()
Dim hMutex As Long
'Try to create a new Mutex
hMutex = CreateMutex(ByVal 0&, 1, App.Title)
'Did the mutex already exist?
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
'Clean up
ReleaseMutex hMutex
CloseHandle hMutex
'More than one instance detected
MsgBox "No se puede ejecutar 2 veces lo mismo"
Hide
'busco la ventana con el mismo nombre de la instancia previa
ventana = FindWindow(vbNullString, Me.Caption)
'llamo al hwnd de la ventana encontrada
Call SetForegroundWindow(ventana)
'muestro ala ventana mediante su hwnd
Call ShowWindow(ventana, SW_NORMAL)
End
End If
End Sub
ayuda y sugerencias.. seran bienvenidas..
Edit: solucionado.
Option Explicit
'Code by Adam Verwijs
Const ERROR_ALREADY_EXISTS = 183&
Private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As Any, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
Private Declare Function ReleaseMutex Lib "kernel32" (ByVal hMutex As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_NORMAL = 1
Dim ventana As Long
Private Sub Form_Load()
Dim hMutex As Long
Me.Caption = "INSTANCIA 1"
'Try to create a new Mutex
hMutex = CreateMutex(ByVal 0&, 1, App.Title)
'Did the mutex already exist?
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
'Clean up
ReleaseMutex hMutex
CloseHandle hMutex
Me.Caption = "INSTANCIA 2"
Hide
'busco la ventana con el mismo nombre de la instancia previa
ventana = FindWindow(vbNullString, "INSTANCIA 1")
'llamo al hwnd de la ventana encontrada
Call SetForegroundWindow(ventana)
'muestro ala ventana mediante su hwnd
Call ShowWindow(ventana, SW_NORMAL)
End
End If
End Sub
Saludos.