|
-
December 11th, 2001, 03:02 AM
#1
Application Instance Already Open ?
Hi Gurus,
How can I prevent my application from being opened more than once ?
Thanks,
Krogoth!
FSM
-
December 11th, 2001, 03:36 AM
#2
Re: Application Instance Already Open ?
There are two techniques to achive this:
1) Using windows API
Const ERROR_ALREADY_EXISTS = 183&
private Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes as Any, byval bInitialOwner as Long, byval lpName as string) as Long
private Declare Function ReleaseMutex Lib "kernel32" (byval hMutex as Long) as Long
private Declare Function CloseHandle Lib "kernel32" (byval hObject as Long) as Long
private Sub Form_Load()
Dim hMutex as Long
hMutex = CreateMutex(byval 0&, 1, App.Title) 'Try to create a Mutex
'Check the mutex already exist or not
If (Err.LastDllError = ERROR_ALREADY_EXISTS) then
'Clean up all
ReleaseMutex hMutex
CloseHandle hMutex
'More than one instance detected
MsgBox "Give your Message"
End
else
'form load code
End If
End Sub
2) Using VB App global Object
private Sub Form_Load()
If App.PrevInstance = true then MsgBox "Give your Message": End
End Sub
programmer at MIND
-
December 11th, 2001, 07:01 AM
#3
Re: Application Instance Already Open ?
You should not use "End" keyword...
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
December 11th, 2001, 08:46 AM
#4
Re: Application Instance Already Open ?
2) Using VB App global Object ( Corrected )
private Sub Form_Load()
If App.PrevInstance = true then
MsgBox "Your Message"
Unload me
End Sub
Nicolas Bohemier
______________
Un sourire ne coûte rien, mais il rapporte beaucoup; il enrichit celui qui le reçoit sans appauvrir celui qui le donne.
Frank Irving Fletcher
Nicolas Bohemier
-
December 12th, 2001, 12:49 AM
#5
Re: Application Instance Already Open ?
Thanks Man...
I will use the second one but will try the first one too ;-)
Krogoth!
FSM
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
|