S
shivaranjani.s.adimulam
Hi,
I have a problem regarding restoring previous instance of an
application minimized in systray.So that when I try to run the
application it should maximize its previous instance instead of
creating a new one.
The part of code is like -
I have one function which returns the instance of the
previous process as
Public Function GetProcess() As Process
'to get the process for the already running application
Dim processes() As Process
Dim procName As String
procName = Process.GetCurrentProcess.ProcessName
processes = Process.GetProcessesByName(procName)
For Each p As Process In processes
If p.Id <> Process.GetCurrentProcess.Id Then
Return p
End If
Next
End Function
In the below function I am trying to display the window but it
doesn't work the main window handle is 0 in this case.
Public Function MultipleInstancesRunning() As Boolean
Dim pInstance As Process
pInstance = GetProcess()
If Not pInstance Is Nothing Then
Dim handle As IntPtr = pInstance.MainWindowHandle
If Not IntPtr.Zero.Equals(handle) Then
ShowWindow(handle, SW_SHOWMAXIMIZED)
SetForegroundWindow(handle)
End If
Return True
Else
Return False
End If
End Function
Is anything wrong with this method? Do anybody knows any other
alternative?
I have a problem regarding restoring previous instance of an
application minimized in systray.So that when I try to run the
application it should maximize its previous instance instead of
creating a new one.
The part of code is like -
I have one function which returns the instance of the
previous process as
Public Function GetProcess() As Process
'to get the process for the already running application
Dim processes() As Process
Dim procName As String
procName = Process.GetCurrentProcess.ProcessName
processes = Process.GetProcessesByName(procName)
For Each p As Process In processes
If p.Id <> Process.GetCurrentProcess.Id Then
Return p
End If
Next
End Function
In the below function I am trying to display the window but it
doesn't work the main window handle is 0 in this case.
Public Function MultipleInstancesRunning() As Boolean
Dim pInstance As Process
pInstance = GetProcess()
If Not pInstance Is Nothing Then
Dim handle As IntPtr = pInstance.MainWindowHandle
If Not IntPtr.Zero.Equals(handle) Then
ShowWindow(handle, SW_SHOWMAXIMIZED)
SetForegroundWindow(handle)
End If
Return True
Else
Return False
End If
End Function
Is anything wrong with this method? Do anybody knows any other
alternative?