D
dotnetme
VB.net (VS 2005)
I have an application using single instance setting in "My Project", Having
some issuses with code I put in "StartupNextInstance" in
"ApplicationEvents"... What works is if I minimize the running application
and then try to start a 2nd instance of the application if it will restore
the minimized running application instead of loading a 2nd instance,Perfect
works as planned!! (code below)
But what doesn't work is if I add code to hide the application and put it in
the taskbar and the try to start a 2nd instance of the application it still
does't allow the 2nd instance but it fails(nothing happens, no errors) to
restore the application to the desktop and give it focus. is this because I
hide the window when it is minimized??? I would like to keep it in the
taskbar is there a solution to make it work? (code below)
Thanks for your help in advance....
dotnetme
'~~~~~~~~~~~~~~~~~~~~
'"ApplicationEvents"
Private Sub MyApplication_StartupNextInstance(ByVal sender As Object, ByVal
e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs)
Handles Me.StartupNextInstance
Dim RunningProcesses As Process() =
Process.GetProcessesByName("Single Instance")
' SW_HIDE = 0
' SW_SHOWNORMAL = 1
' SW_NORMAL = 1
' SW_SHOWMINIMIZED = 2
' SW_SHOWMAXIMIZED = 3
' SW_MAXIMIZE = 3
' SW_SHOWNOACTIVATE = 4
' SW_SHOW = 5
' SW_MINIMIZE = 6
' SW_SHOWMINNOACTIVE = 7
' SW_SHOWNA = 8
' SW_RESTORE = 9
' SW_SHOWDEFAULT = 10
' SW_FORCEMINIMIZE = 11
' SW_MAX = 11
If (RunningProcesses.Length > 1) Then
ShowWindowAsync(RunningProcesses(0).MainWindowHandle, 1)
ShowWindowAsync(RunningProcesses(0).MainWindowHandle, 9)
End If
End Sub
'~~~~~~~~~~~~~~~~~~~~~~
'"Form1" - hide window and put in taskbar
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
If (Me.WindowState = FormWindowState.Minimized) Then
Me.Hide()
taskbar1.Visible = True
taskbar1.Text = "Single Instance"
End If
End Sub
I have an application using single instance setting in "My Project", Having
some issuses with code I put in "StartupNextInstance" in
"ApplicationEvents"... What works is if I minimize the running application
and then try to start a 2nd instance of the application if it will restore
the minimized running application instead of loading a 2nd instance,Perfect
works as planned!! (code below)
But what doesn't work is if I add code to hide the application and put it in
the taskbar and the try to start a 2nd instance of the application it still
does't allow the 2nd instance but it fails(nothing happens, no errors) to
restore the application to the desktop and give it focus. is this because I
hide the window when it is minimized??? I would like to keep it in the
taskbar is there a solution to make it work? (code below)
Thanks for your help in advance....
dotnetme
'~~~~~~~~~~~~~~~~~~~~
'"ApplicationEvents"
Private Sub MyApplication_StartupNextInstance(ByVal sender As Object, ByVal
e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs)
Handles Me.StartupNextInstance
Dim RunningProcesses As Process() =
Process.GetProcessesByName("Single Instance")
' SW_HIDE = 0
' SW_SHOWNORMAL = 1
' SW_NORMAL = 1
' SW_SHOWMINIMIZED = 2
' SW_SHOWMAXIMIZED = 3
' SW_MAXIMIZE = 3
' SW_SHOWNOACTIVATE = 4
' SW_SHOW = 5
' SW_MINIMIZE = 6
' SW_SHOWMINNOACTIVE = 7
' SW_SHOWNA = 8
' SW_RESTORE = 9
' SW_SHOWDEFAULT = 10
' SW_FORCEMINIMIZE = 11
' SW_MAX = 11
If (RunningProcesses.Length > 1) Then
ShowWindowAsync(RunningProcesses(0).MainWindowHandle, 1)
ShowWindowAsync(RunningProcesses(0).MainWindowHandle, 9)
End If
End Sub
'~~~~~~~~~~~~~~~~~~~~~~
'"Form1" - hide window and put in taskbar
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
If (Me.WindowState = FormWindowState.Minimized) Then
Me.Hide()
taskbar1.Visible = True
taskbar1.Text = "Single Instance"
End If
End Sub