1: public struct RECT
2: {
3: public int left;
4: public int top;
5: public int right;
6: public int bottom;
7: }
8:
9: public static class NativeMethods
10: {
11: public const UInt32 WM_MOVE = 0x0003;
12:
13: [DllImport("kernel32.dll")]
14: public static extern IntPtr GetConsoleWindow();
15:
16: [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
17: public static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
18:
19: /// <summary>
20: /// The MoveWindow function changes the position and dimensions of the specified window. For a top-level window, the position and dimensions are relative to the upper-left corner of the screen. For a child window, they are relative to the upper-left corner of the parent window's client area.
21: /// </summary>
22: /// <param name="hWnd">Handle to the window.</param>
23: /// <param name="X">Specifies the new position of the left side of the window.</param>
24: /// <param name="Y">Specifies the new position of the top of the window.</param>
25: /// <param name="nWidth">Specifies the new width of the window.</param>
26: /// <param name="nHeight">Specifies the new height of the window.</param>
27: /// <param name="bRepaint">Specifies whether the window is to be repainted. If this parameter is TRUE, the window receives a message. If the parameter is FALSE, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of moving a child window.</param>
28: /// <returns>If the function succeeds, the return value is nonzero.
29: /// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para></returns>
30: [DllImport("user32.dll", SetLastError = true)]
31: public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
32:
33: [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
34: public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
35: }