3

I want to minimize a window using C#

Ex : I have opened this path E:\ using

process.start(E:\)

And I want to minimize this path on a certain event.

How can I make that possible?

nawfal
  • 70,104
  • 56
  • 326
  • 368
cool buzz
  • 129
  • 2
  • 6

5 Answers5

2

The following sample Console Application code will minimize all shell explorer views that are opened on E:\ :

class Program
{
    static void Main(string[] args)
    {
        // add a reference to "Microsoft Shell Controls and Automation" COM component
        // also add a 'using Shell32;'
        Shell shell = new Shell();
        dynamic windows = shell.Windows(); // this is a ShellWindows object
        foreach (dynamic window in windows)
        {
            // window is an WebBrowser object
            Uri uri = new Uri((string)window.LocationURL);
            if (uri.LocalPath == @"E:\")
            {
                IntPtr hwnd = (IntPtr)window.HWND; // WebBrowser is also an IWebBrowser2 object
                MinimizeWindow(hwnd);
            }
        }
    }

    static void MinimizeWindow(IntPtr handle)
    {
        const int SW_MINIMIZE = 6;
        ShowWindow(handle, SW_MINIMIZE);
    }

    [DllImport("user32.dll")]
    private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}

It's using the Shell Objects for Scripting. Note the usage of the dynamic keyword that's mandatory here because there is no cool typelib, and therefore no intellisense either.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
1

Shell32.Shell objShell = new Shell32.Shell(); objShell.MinimizeAll(); this will help you to minimize all the window Not only Folders all(something like windows + M!!!

Pravee
  • 85
  • 1
  • 10
0

Your question is not very clear. If you are using a TreeView control see MSDN Treeview class. You can then: Expand or Collapse items at will.

0

You can use the configuration file or a Variable

0

This is a possible solution and only minimizes the window u opened:

private int explorerWindowNumber;
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MINIMIZE = 0xF020;

[DllImport("user32.dll", SetLastError = true)]
public static extern int GetForegroundWindow();

[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

public void button1_Click(object sender, EventArgs e)
{
    //Start my window
    StartMyExplorer();
}

private void StartMyExplorer()
{
    Process.Start("D:\\");
    Thread.Sleep(1000);
    //Get the window id (int)
    explorerWindowNumber = GetForegroundWindow();
}

private void button2_Click(object sender, EventArgs e)
{
    //Minimize the window i created
    SendMessage(explorerWindowNumber, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
Jim
  • 2,974
  • 2
  • 19
  • 29