I went to MSDN to read up on the Atom functions and I can now see what UEZ and jj2007 are saying.jj2007 wrote:As UEZ noted, the MessageBox serves only to simulate the running program. When it finishes, the atom must be deleted.
So, with jj2007's original code the MessageBox is dual purpose: Firstly to tell us of a sucessful start; Secondly to simulate running code. However, the second purpose is not explained to us. When UEZ replaced the MessageBox with Sleep no explanation is given there either.
jj2007's original code with an explanation could be:
Code: Select all
#include "Windows.bi"
Dim ItsMe as string=Command(0)
If GlobalFindAtom(ItsMe) Then
Messagebox Null, ItsMe+" is already running", "Sorry:", MB_IconWarning Or MB_Topmost
else
Dim IsRunning as short=GlobalAddAtom(ItsMe)
' ##########
'
' <-- Your application here
'
' ##########
GlobalDeleteAtom(IsRunning)
End If
To test the method replace '<-- Your application here' with either a MessageBox or Sleep.
I take the view that is convoluted code.
With my method I simply add a simple construct to my application.
Code: Select all
If FirstInstanceOfProgram = 0 Then
Messagebox Null, "<Whatever> is already running", "Title", MB_IconWarning Or MB_TaskModal Or MB_Topmost
End
End If