static void Main() { SafeFileHandle handle = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); if (handle.IsInvalid) { Console.WriteLine("Konnte kein Handle für die Konsole bekommen :("); return; } SmallRect screenRectangle = new SmallRect(0, Widht, 0, Height); Coord topLeft = new Coord { X = 0, Y = 0 }; Coord bottomRight = new Coord { X = Widht, Y = Height }; FPS fpsCounter = new FPS(); Console.CursorVisible = false; Console.ForegroundColor = ConsoleColor.Yellow; TextBox tbTest = new TextBox(new Point(rndGen.Next(20), rndGen.Next(20)), ConsoleColor.Red); TextBox tbTest2 = new TextBox(new Point(rndGen.Next(20), rndGen.Next(20)), ConsoleColor.Red); TextBox tbTest3 = new TextBox(new Point(rndGen.Next(20), rndGen.Next(20)), ConsoleColor.Red); DVD dvd = new DVD(); DVD dvd2 = new DVD(); DVD dvd3 = new DVD(); ConsoleKey key = ConsoleKey.Attention; do { fpsCounter.Draw(); tbTest.Draw(); tbTest2.Draw(); tbTest3.Draw(); dvd.Draw(); dvd2.Draw(); dvd3.Draw(); WriteConsoleOutput(handle, ScreenBuffer, bottomRight, topLeft, ref screenRectangle); if (!Console.KeyAvailable) { continue; } // code only processed when a key is down key = Console.ReadKey(true).Key; switch (key) { default: tbTest.ProcessKey(key); break; } } while (key != ConsoleKey.Escape); }
static extern bool WriteConsoleOutput( SafeFileHandle hConsoleOutput, CharInfo[] lpBuffer, Coord dwBufferSize, Coord dwBufferCoord, ref SmallRect lpWriteRegion);
static void Main() // static bedeutet das diese methode auf Klassenebene ist, also keinem einzelnen // Objekt direkt zugeordnet ist. Name muss so gewählt sein da windows sonst nicht weiss wo es beginnen // muss { SafeFileHandle handle = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); if (handle.IsInvalid) { Console.WriteLine("Konnte kein Handle für die Konsole bekommen :("); return; } SmallRect screenRectangle = new SmallRect(0, 80, 0, 25); Coord topLeft = new Coord { X = 0, Y = 0 }; Coord bottomRight = new Coord { X = 80, Y = 25 }; FPS fpsCounter = new FPS(); Console.CursorVisible = false; Console.ForegroundColor = ConsoleColor.Yellow; TextBox tbTest = new TextBox(new Point(2, 2), ConsoleColor.Red); DVD dvd = new DVD(); ConsoleKey key = ConsoleKey.Attention; do { fpsCounter.Draw(); //tbTest.Draw(); dvd.Draw(); WriteConsoleOutput(handle, ScreenBuffer, bottomRight, topLeft, ref screenRectangle); if (!Console.KeyAvailable) { continue; } // code only processed when a key is down key = Console.ReadKey(true).Key; switch (key) { case ConsoleKey.UpArrow: break; case ConsoleKey.DownArrow: break; case ConsoleKey.Enter: break; default: tbTest.ProcessKey(key); break; } } while (key != ConsoleKey.Escape); Console.ResetColor(); }