stil
stil

Reputation: 5556

How to restore a minimized window having only its handle

Process[] procs = Process.GetProcesses();
IntPtr hWnd;
foreach (Process proc in procs)
{
    if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
    {
        Debug.WriteLine("{0} : {1}", proc.ProcessName, hWnd);
    }
}

My question is, how can I restore minimized window having its handle (hWnd variable).

I would be grateful if you could also supply with some documentation of window handlers so I can see how to manipulate them.

Upvotes: 0

Views: 137

Answers (1)

Teagan42
Teagan42

Reputation: 628

Unless you're in the same application domain, you'll have to use an unmanaged API to do this.

private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
private void restoreWindow(IntPtr hWnd)
{
    if (!hWnd.Equals(IntPtr.Zero))
    {
        ShowWindowAsync(hWnd, SW_SHOWMAXIMIZED);
    }
}

https://msdn.microsoft.com/en-us/library/ms633549(VS.85).aspx

Upvotes: 2

Related Questions