1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
[DllImport("kernel32")]
private static extern IntPtr GetConsoleWindow();
[DllImport("user32")]
private static extern Boolean GetClientRect(IntPtr hWnd, ref Rectangle rect);
[DllImport("user32")]
private static extern Boolean SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags);
private static int STD_OUTPUT_HANDLE = -11;
private static int SWP_NOZORDER = 0x4;
private static int SWP_NOACTIVATE = 0x10;
//Configurer la fenêtre de la Console
private static void FenêtreConsole()
{
// - le titre
Console.Title = "ConsoleTest : db4oClassLibrarySample";
// - la position
Int32 x; Int32 y; Int32 width; Int32 height;
GetWindowPosition(out x, out y, out width, out height);
SetWindowPosition(x, y, width, height);
// - le taille
Console.SetWindowSize(Console.LargestWindowWidth - 3, Console.LargestWindowHeight - 3);
}
private static void GetWindowPosition(out Int32 x, out Int32 y, out Int32 width, out Int32 height)
{
Rectangle rect = new Rectangle();
GetClientRect(GetConsoleWindow(), ref rect);
x = rect.Top;
y = rect.Left;
width = rect.Right - rect.Left;
height = rect.Bottom - rect.Top;
}
private static void SetWindowPosition(Int32 x, Int32 y, Int32 width, Int32 height)
{
SetWindowPos(GetConsoleWindow(), IntPtr.Zero, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
} |
Partager