Can we write a api which will detect whether a particular programm is running and also bring the program to the front of the screen.
Can we write a api which will detect whether a particular programm is running and also bring the program to the front of the screen.
use the following code... in you form...
call the following function in your form load event..
if the function parameter is not 1 it will just get the form to foreground..
else if the parameter is 1 it will get the previous instance to foreground and terminate the current instance..
Public Sub ShowPrevInstance(x As Integer)
On Error Resume Next
Dim OldTitle As String
Dim ll_WindowHandle As Long
OldTitle = App.Title
If x = 1 Then App.Title = "New App - This App Will Be Closed"
ll_WindowHandle = FindWindow("ThunderRT5Main", OldTitle)
'if you are using vb6.0 then use ThunderRT6Main instead of ThunderRT5Main
If ll_WindowHandle = 0 Then Exit Sub
ll_WindowHandle = GetWindow(ll_WindowHandle, GW_HWNDPREV)
Call OpenIcon(ll_WindowHandle)
Call SetForegroundWindow(ll_WindowHandle)
If x = 1 Then Unload Me
End Sub