Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Allow Only 1 Instance Of Your Program (And Activate Previous
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Aug 14th, 2004 05:49 AM    Post subject: Allow Only 1 Instance Of Your Program (And Activate Previous Reply with quote

Module Code:
[vb:1:53e81edb03]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 OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long

Public Const GW_HWNDPREV = 3[/vb:1:53e81edb03]

Form Code:
[vb:1:53e81edb03]Private Sub ShowPrevInstance()
Dim OldTitle As String
Dim ll_WindowHandle As Long
'saving the current title in OldTitle variable
'and changing the application title
OldTitle = App.Title
App.Title = "abcba - This App Will Be Closed"
'finding the previous instance. if you are using VB 5.0,
'change "ThunderRT6Main" to "ThunderRT5Main"
ll_WindowHandle = FindWindow("ThunderRT6Main", OldTitle)
'if there is no old instances of your application - exit.
If ll_WindowHandle = 0 Then Exit Sub
'Find the window we need to restore
ll_WindowHandle = GetWindow(ll_WindowHandle, GW_HWNDPREV)
'Now restore it
Call OpenIcon(ll_WindowHandle)
'And Bring it to the foreground
Call SetForegroundWindow(ll_WindowHandle)

End

End Sub

Private Sub Form_Load()
If App.PrevInstance Then ShowPrevInstance
End Sub[/vb:1:53e81edb03]
_________________
Code Snippets, Tutorials, Utilities, Controls

Low cost Web Hosting
Hosting starts at as low as $4 per year!


Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags!
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic