how to suppress multiple instances of any program by (too) fast a double click ???
Printable View
how to suppress multiple instances of any program by (too) fast a double click ???
Here the sample code :)
Code:Option Explicit
'//WIN32API Function
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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
'//WIN32API Constant
Private Const SW_RESTORE = 9
Sub Main()
Dim hwnd As Long
'//Check for Previous Instance
If App.PrevInstance Then
hwnd = FindWindow(0&, "App Window Title Here")
If hwnd <> 0 Then
SetForegroundWindow hwnd
ShowWindow hwnd, SW_RESTORE
End
End If
End If
'//Continue load the Main Form
Load frmMain
frmMain.Show
End Sub
Or you can use the PrevInstance property of the App.
Code:If App.PrevInstance = True Then Unload Me
Meg, i think it will be better if make the previous instance become the active window. like what I did in my posted code?
That's not of the matter though. I was only demonstrating a simpler way of achieveing the same thing (checking for the previous instance).