We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Activating existing instance of application when it''s in the system tray

Thread ID:

Created:

Platform:

Replies:

12768 Apr 12,2004 11:17 AM UTC Windows Forms 0
loading
Tags: FAQ
Patrick Ransom
Asked On April 12, 2004 11:17 AM UTC

Hello, I have posted this question before elsewhere but haven''t gotten any resolution. I have an application that we''ve written, that if it''s running and minmized in the system tray, and the application is ran again .. we are trying to activate the existing instance of the application. If the application is minimize to the task bar, the code bloew works fine, however if it is in the system tray, I can''t get it to maximize and become the active window. Any suggestions? I am pretty much dead in the water at this point. Here''s my code sample: Imports System.Threading Imports System.Diagnostics.Process Imports Microsoft.Win32 Imports System Public Sub Main() ''------------------------------------------------------------------------ '' Make sure that there are no other instances of my application running ''------------------------------------------------------------------------ Dim strCurrentProcessName = System.Diagnostics.Process.GetCurrentProcess().ProcessName Dim intHandle As IntPtr Dim runningProc As Process Dim i As Integer Dim test Dim sWindowTitle as string = "MyApplication" If System.Diagnostics.Process.GetProcessesByName(strCurrentProcessName).Length > 1 Then For i = 0 To System.Diagnostics.Process.GetProcessesByName(strCurrentProcessName).Length - 1 If Process.GetProcessesByName(strCurrentProcessName)(i).Id <> Process.GetCurrentProcess().Id Then runningProc = Process.GetProcessesByName(strCurrentProcessName)(i) intHandle = runningProc.MainWindowHandle If IntPtr.Zero.Equals(intHandle) Then Debug.WriteLine("no window handle if minimized to tray (hidden, no main window)") Debug.WriteLine("we try the native Win32 find features") Debug.WriteLine("sWindowTitle=" & sWindowTitle) intHandle = FindWindow(Nothing, sWindowTitle) If IntPtr.Zero.Equals(intHandle) Then Debug.WriteLine("still no handle") Else Debug.WriteLine("finally have a handle") End If End If Debug.WriteLine("intHandle=" & intHandle.ToString) If IsIconic(intHandle.ToInt32) Then Debug.WriteLine("Was minimized in the taskbar.") System.Runtime.InteropServices.APIs.APIsUser32.ShowWindow(intHandle, Runtime.InteropServices.APIs.APIsEnums.ShowWindowStyles.RESTORE) Win32Helper.SetForegroundWindow(intHandle) Else '' This is where I can not get it to come out of the system tray Debug.WriteLine("not iconic") System.Runtime.InteropServices.APIs.APIsUser32.ShowWindow(intHandle, Runtime.InteropServices.APIs.APIsEnums.ShowWindowStyles.MAXIMIZE) Win32Helper.SetForegroundWindow(intHandle) End If End If Next Exit Sub End If ... ... ...

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;