2011-11-04 231 views
4

是否可以從另一個應用程序中調整正在運行的應用程序的窗口大小? 我希望當我正在構建的應用程序開始時,另一個應用程序(比如說itunes)的寬度將減少到2/3,以便剩餘的1/3可以被我的應用程序佔用。這兩個應用程序應該完全運行並且可以由用戶訪問。 請儘可能幫忙。調整窗口大小C#

回答

10

您可以使用SetWindowPos調整其他進程的窗口大小。

[DllImport("user32.dll")] 
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, 
     int x, int y, int width, int height, uint uFlags); 

    private const uint SHOWWINDOW = 0x0040; 

    private void resizeItunes() 
    { 
     System.Diagnostics.Process[] itunesProcesses = 
      System.Diagnostics.Process.GetProcessesByName("iTunes"); 

     if (itunesProcesses.Length > 0) 
     { 
      SetWindowPos(itunesProcesses[0].MainWindowHandle, this.Handle, 
       0, 0, Screen.GetWorkingArea(this).Width * 2/3, 
       Screen.GetWorkingArea(this).Height, SHOWWINDOW); 
     } 
    } 
+0

非常感謝。這將幫助我開始 –

+0

+1;不錯,簡單,比我的答案要好。 – AMissico

+0

這絕對是答案。 –