Buenas foro, estaba haciendo un soft y me tope con la siguiente duda:
Si yo hago que mi soft se minimize en la bandeja de Tray (Junto al reloj), y el usuario, vuelve a ejecutar el programa desde el "Programa.exe", Como hago para que se habra el "FormMain" por ejemplo pero de la instancia que esta minimizada, es decir:
Citar
Private Sub Form_Load()
If App.PrevInstance = True Then
'abrir el FrmMain que esta minimizado
End If
End Sub
* mi duda seria que pongo en lugar de "'abrir el FrmMain que esta minimizado"
Gracias
Hola, este es un ejemplo de como hacer que te parpadee la ventana si a tenes ya abierta.
Option Explicit
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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
Const ERROR_ALREADY_EXISTS = 183&
Private Sub Form_Initialize()
Dim hMutex As Long
Dim vRet As Long
hMutex = CreateMutex(ByVal 0&, 1, App.Title)
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
ReleaseMutex hMutex
CloseHandle hMutex
vRet = FindWindow("ThunderRT6FormDC", "Form1")
FlashWindow vRet, 1
End
End If
End Sub
adaptalo al tuyo..
saludos.
PrevInstance no sirve si cambian de nonbre o ruta
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Sub Form_Load()
Dim CaptionVerdadero As String: CaptionVerdadero = Me.Caption
If App.PrevInstance Then
Me.Caption = "INSTANCIA 2"
Call ShowWindow(FindWindow(vbNullString, CaptionVerdadero), 1)
Call SetForegroundWindow(FindWindow(vbNullString, CaptionVerdadero))
End
End If
End Sub
Fijate esto
http://foro.elhacker.net/empty-t261721.0.html (http://foro.elhacker.net/empty-t261721.0.html)
Cita de: Hasseds en 16 Enero 2010, 19:35 PM
PrevInstance no sirve si cambian de nonbre o ruta
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Sub Form_Load()
Dim CaptionVerdadero As String: CaptionVerdadero = Me.Caption
If App.PrevInstance Then
Me.Caption = "INSTANCIA 2"
Call ShowWindow(FindWindow(vbNullString, CaptionVerdadero), 1)
Call SetForegroundWindow(FindWindow(vbNullString, CaptionVerdadero))
End
End If
End Sub
Fijate esto
http://foro.elhacker.net/empty-t261721.0.html (http://foro.elhacker.net/empty-t261721.0.html)
Gracias
Hasseds tu Code funciono perfecto Gracias
agus, tené en cuenta que PrevInstance no sirve en el caso de que alguien modifique el nombre o la ruta del ejecutable, si bien esto se puede manejar con App.EXEName y App.Path lo correcto seria CreateMutex. como te indica Seba o que adaptes el code de byway.
Un saludo agus ;)