2014-01-12 60 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); 
}