2014-01-12 34 views
3

我想用C#最小化文件夹

EX并最小化窗口:我已经打开使用

process.start(E:\) 

这条道路E:\我希望尽量减少对某个事件的这条道路。

我该如何做到这一点?

+0

尝试发送键WIN +向下箭头,http://msdn.microsoft.com/en-us/library/system.windows .forms.sendkeys.send%28v = vs.110%29.aspx –

+0

希望这篇文章有帮助http://stackoverflow.com/questions/785054/minimizing-all-open-windows-in-c-sharp –

回答

0

你的问题不是很清楚。如果您使用的是TreeView控件,请参阅 MSDN Treeview class。然后您可以:随意展开或折叠项目。

1

Shell32.Shell objShell = new Shell32.Shell(); objShell.MinimizeAll(); 这将帮助你最小化所有窗口,不仅文件夹的所有(有点像窗+ M!

+2

OP的问题不是为了尽量减少所有的窗户,而是尽量减少他以前打开的路径 – Jim

+0

你知道答案吗?我现在也在寻找相同的东西! – Pravee

+0

或'objShell.ToggleDesktop'来显示桌面(和切换),相当于windows + D :) – nawfal

2

下面的示例控制台应用程序代码将减少这是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); 
} 

它使用Shell Objects for Scripting注意动态关键字这是强制性这里的使用,因为没有凉类型库,因此没有智能感知要么

0

这是一个可能的解决方案,只是最小化ü打开窗户:

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); 
}