Originally posted by hspc
anyway this is my solution for this prolem :
How does it work ?
it creates a mutex (shared object that hace a uniqe name)..
if you try to recreate it you get the error : ERROR_ALREADY_EXISTS
this is the whole idea...
I like your solution.
Another way (not this good, however)
is to have a check in sub main for a particular form
(FindWindow api will find it even if it is not visible)
you load and do not show. If you find it, program is
already running, if not, it is first instance
ie attached code
But your solution is better...
...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.
If anyone is interested, here is my solution to PreviousInstance : DDE or LinkItem as VB call it.
On the main form, have these properties set :
LinkMode : 1 - Source
LinkTopic : "AppLinkTopic" [Can be anything]
Then on my Form Load using an invisible textbox I named TxtDDE :
TxtDDE.LinkMode = 0 ' None
TxtDDE.LinkTopic = "YourApplicationTitleHere|AppLinkTopic"
On Error goto NoDDE
TxtDDE.LinkMode = 2 ' Manual - Link to existing dde host
TxtDDE.LinkExecute "SHOWUP" ' When host receive this, it should activate itself
' Continu loading here.
Here is the code I use to deal with the SHOWUP command (on the main form) :
Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
If (UCase(CmdStr) = "SHOWUP") Then
FrmMain.Visible = True
FrmMain.WindowState = vbNormal
' I use the same method to notify my application to quit ( for updates )
If (UCase(CmdStr) = "QUIT") Then FrmLoad.Menu_TrayQuit_Click