Search code examples
c#restoresystem-tray

How can I restore a window of a program minimized into tray


Possible Duplicate:
Restore a minimized window of another application

I want to restore (show and give focus) to an external program.

The problem is that if it is on the tray the MainWindowHandle is 0, so I can not restore the window.

Process[] process = Process.GetProcessesByName("MyApp");
//process.MainWindowHandle  == 0 if it is on tray!! :(

I've already searched google and stackoverflow. I found some threads with the same question, but there is no answer to this.

[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr windowHandle, ShowWindowFlag flag);

How can I pop the external application out of tray and bring it to taskbar?


I can use FindWindow,

    [DllImport("User32.dll", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(string className, string windowName);

but if there is more the one process with the same class and title, FindWindow will return only one of them, how can i solve this?


Solution

  • The thing is, that Windows does not have a support to minimize the window into system tray. There is no such state. And in order to simulate this behavior applications simply hide the windows totally. You can use Spy++ tool to find the window of your target app while it is visible. Then "minimize" it to tray, and see what was changed in the attributes. Then in your app you should revert the attributes. This is needed, because there several ways to hide a window and different apps use one of them.

    For example Windows Task Manager change the style from VS_VISIBLE to VS_MINIMIZED (and remove VS_VISIBLE).