Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change another program's window's size?

Tags:

c#

winapi

How can I change another program's -- let's say Skype's -- window's size, from my C# program?

like image 383
funerr Avatar asked Dec 09 '11 09:12

funerr


People also ask

How do I change the size of my Windows program?

Press-and-hold Alt, then middle-click near the corner that you want to resize. The mouse pointer changes to indicate that you can resize from the corner. To resize the window, drag from the corner on which you middle-clicked. To resize a window horizontally point to one of the vertical edges of the window.

How do I resize a program in Windows 10?

Press Alt + Space shortcut keys together on the keyboard to open the window menu. Use the left, right, up and down arrow keys to resize your window.


2 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).

like image 132
Lloyd Powell Avatar answered Sep 28 '22 07:09

Lloyd Powell


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.

like image 37
Matten Avatar answered Sep 28 '22 06:09

Matten