Interop.RuntimeServices.Pinvoke.MoveWindow

Move external application using MoveWindow Windows API
void Main()
{
	var notepad = Process.GetProcessesByName("notepad").Single();
	
	var rect = new Rect();
	GetWindowRect(notepad.MainWindowHandle, ref rect);
	MoveWindow(notepad.MainWindowHandle, 200, 200, rect.Right - rect.Left, rect.Bottom - rect.Top, true);
}

internal struct Rect
{
	public int Left;
	public int Top;
	public int Right;
	public int Bottom;
}

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
internal static extern bool GetWindowRect(IntPtr handle, ref Rect rect);

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
internal static extern void MoveWindow(IntPtr handle, int x, int y, int width, int height, bool repaint);

Last edited May 2, 2012 at 5:13 AM by teoarch, version 1

Comments

No comments yet.