|
-
Jun 22nd, 2005, 10:42 AM
#1
application already running?!?!
hi all!!
how can i check if my application is already running or not?
if it is then how can i display that "the application is already running."??
thnx
-
Jun 22nd, 2005, 10:46 AM
#2
Re: application already running?!?!
App.PrevInstance, will detect if it is already running
you can then display a message box, or exit the program
pete
-
Jun 22nd, 2005, 10:54 AM
#3
Re: application already running?!?!
-
Jun 23rd, 2005, 04:24 AM
#4
Fanatic Member
Re: application already running?!?!
A neater option if a previous instance of the application is running is just to switch to it:
VB Code:
Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) _
As Long
Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Public Sub Main()
If App.PrevInstance Then
ActivatePrevInstance
End If
'Etc......
End sub
Public Sub ActivatePrevInstance()
Dim OldTitle As String, PrevHndl As Long
Dim Result As Long
'Save the title of the application.
OldTitle = App.Title
'Rename the title of this application so FindWindow
'will not find this application instance.
App.Title = "Duplicate instance"
'Attempt to get window handle using VB4 class name.
PrevHndl = FindWindow("ThunderRTMain", OldTitle)
'Check for no success.
If PrevHndl = 0 Then
'Attempt to get window handle using VB5 class name.
PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
End If
'Check if found
If PrevHndl = 0 Then
'Attempt to get window handle using VB6 class name
PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
End If
'Check if found
If PrevHndl = 0 Then
'No previous instance found.
Exit Sub
End If
'Get handle to previous window.
PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)
'Restore the program.
Result = OpenIcon(PrevHndl)
'Activate the application.
Result = SetForegroundWindow(PrevHndl)
'End the application.
End
End Sub
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Jun 23rd, 2005, 04:38 AM
#5
Re: application already running?!?!
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
|