|
-
October 1st, 2001, 08:27 AM
#2
Re: Running only 1 instance
You can use App.PrevInstance. But from my experience sometimes it is not very stable. For example when you kill the second instance of the app and check the task list you might still have your app running there.
I prefer to use API. Here is an example
'module declarations
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Constants used by the API functions
Public Const WM_CLOSE = &H10
'in the form
Private Sub Form_Load()
'========================================================================
If App.PrevInstance Then KillSecondApp
End Sub
Private Sub KillSecondApp()
'=============================================================================
Dim hWindow As Long
Dim lngReturnValue As Long
hWindow = FindWindow(vbNullString, "Your Window Caption")
lngReturnValue = PostMessage(hWindow, WM_CLOSE, vbNull, vbNull)
End Sub
Iouri Boutchkine
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|