Hi,

I have an application runnig. i want only one instance of it on my system. So i check for the previous instance and then if exist i get the handle and then set that window as fore ground window .. But it is not working fine.. Can any body help me out..

i am sending the code..

Sub Main()

Dim handle As Long
Dim lng As Long
Dim SaveTitle As String

If (App.PrevInstance) Then
SaveTitle = App.Title

handle = FindWindow(0&, "My Application")


If handle = 0 Then
handle = FindWindow(0&, SaveTitle)

End If


lng = BringWindowToTop(handle)

lng = SetForegroundWindow(handle)


If lng = 0 Then

MsgBox "Previous instance not found ", vbInformation

End If


'Kill the Duplicate Instance of the Application in any case.
End

End If
frmMyapplication.Show
End Sub




Reply ASAP

Pradeep