C # window resizing

Can I resize the application launch window from another application? I want that when starting the application that I am creating, the width of another application (even itunes) will be reduced to 2/3, so that the remaining 1/3 will be occupied by my application. Two applications should work fully and are accessible to the user. Please help if possible.

+4
source share
2 answers

You can use SetWindowPos to resize another process window.

  [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); } } 
+10
source

You need to get the Windows handle, so use the FindWindow function http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx , then pass the handle to the window using SendMessage .

You need SendMessage at http://msdn.microsoft.com/en-us/library/ms644950.aspx or PostMessage at http://msdn.microsoft.com/en-us/library/ms644944(VS.85).aspx with WM_SIZE (0x0005) and specify the size.

+4
source

Source: https://habr.com/ru/post/1379580/


All Articles