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 :
Code:
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
Unload Me
End
NoDDE:
' Continu loading here.
Here is the code I use to deal with the SHOWUP command (on the main form) :
Code:
Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
If (UCase(CmdStr) = "SHOWUP") Then
FrmMain.Visible = True
FrmMain.WindowState = vbNormal
FrmMain.SetFocus
End If
' I use the same method to notify my application to quit ( for updates )
If (UCase(CmdStr) = "QUIT") Then FrmLoad.Menu_TrayQuit_Click
End Sub
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.