-
If i am using both the Win.ini and registry to boot an application, how can i make it so that only one instance of the application will run?
Essentially i want it to check if the app is already open, if so unload itself, if not continue to load itself.
Can i set this to happen on splash screen ini?
Any help would be appreciated.
-
Code:
If App.PrevInstance Then
Unload Me
End If
-
Thankyou for that.
Works a treat.
Regards
M.
-
here is one step further
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd&, ByVal nCmdShow&) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd&) As Long
Private Const SW_RESTORE = 9
Public Sub Main()
Dim sTitle$
Dim lRetVal&, hwnd&
If App.PrevInstance Then 'only allows 1 instance of app to be open at a time
sTitle = mdiMain.Caption
App.Title = "newcopy"
mdiMain.Caption = "newcopy"
hwnd = FindWindow(vbNullString, sTitle)
If hwnd <> 0 Then
lRetVal = ShowWindow(hwnd, SW_RESTORE)
lRetVal = SetForegroundWindow(hwnd)
End If
End
Else
mdiMain.Show
End If
End Sub