hi,
imagine that i have a app running and i try to launch that app again by click in the exe file, there is any way to restore,call,send a message to the app that is already running instead add a new app running?
thanks a lot for your help
Printable View
hi,
imagine that i have a app running and i try to launch that app again by click in the exe file, there is any way to restore,call,send a message to the app that is already running instead add a new app running?
thanks a lot for your help
Do you mean you want to stop the second instance from starting?
hi,
i want stop the secund instance and maximize the other instance that is already running
Try thisCode:Private Sub Form_Load()
'this should go in your startup form
If App.PrevInstance = True Then
MsgBox "Application Is Already Running", vbInformation + vbOKOnly, "Only One Instance Allowed"
End 'yes, the dreaded end - the only place I've ever found a use for it
End If
End Sub
yes this solve the first problem but don“t restore/maximize the other app
how can i call the other app that is running in first place?
You can do something like this...
' Main form...
Code:Option Explicit
Private terminate_app As Boolean
Private Const SW_MAXIMIZE = 3
Private Const SW_SHOW = 5
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Code:Private Sub PrevInstance(FrmToShow As Form)
' Call this sub from your start-up form.
' Restores the 1st instance of your program by Hwnd.
Dim Lng As Long
If App.PrevInstance Then
Lng = GetSetting("MyCompanyNameHere", App.Title, "Hwnd", 0)
If Lng > 0 then
ShowWindow Lng, SW_SHOW
ShowWindow Lng, SW_MAXIMIZE
SetForegroundWindow Lng
terminate_app = True
Exit Sub
End If
Else
SaveSetting "MyCompanyNameHere", App.Title, "Hwnd", FrmToShow.hwnd
End If
End Sub
In the form unload you can then check terminate_app , if it's = True then don't save any user settings.Code:Private Sub Form_Load()
PrevInstance Me ' is a copy already running?
If terminate_app = True Then ' if true then exit!
Unload Me
Exit Sub
End If
End Sub
hi,
thanks a lot this work as i needed :)