How can I change another program's -- let's say Skype's -- window's size, from my C# program?
-
http://stackoverflow.com/questions/692742/how-do-you-programmatically-resize-and-move-windows-with-the-windows-api – Jahan Zinedine Dec 09 '11 at 09:36
-
If you break up this problem into two (1. How to affect another process' windows; 2. How to change any window's size) you should be able to find answers on Stack Overflow. PS: What if the foreign application has several windows open? Which one would you want to manipulate? – stakx - no longer contributing Dec 09 '11 at 09:41
3 Answers
You can use MoveWindow (Where hWnd is the window you want to move):
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
MoveWindow(ApplicationHandle, 600, 600, 600, 600, true);
If you don't know the window pointer, you can use the FindWindow functionality.
Also worth a read is MSDN SetWindowPos (Very similar to MoveWindow).

- 11,267
- 8
- 44
- 37

- 18,270
- 17
- 87
- 123
You need to get the window handle of the other program, use Process.MainWindowHandle or FindWindow.
Having this, you can PInvoke SetWindowPos() to move, resize, change the Z-order or the min/max/restore state of the window.

- 922,412
- 146
- 1,693
- 2,536

- 17,365
- 2
- 42
- 64
I would use the Windows Api SetWindowPos
check this one out: Using SetWindowPos in C# to move windows around
of course first you should know the handle of the window you want to resize, this can be done in many ways like getting the process by name then the MainWindow of that process or with EnumWindow
or FindWindow
APIs

- 1
- 1

- 43,984
- 10
- 98
- 147