private static ConsoleHandle HandleInvalidHandle(ConsoleHandle handle, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string callerName = "", [CallerFilePath] string filePath = "") { if (handle.IsInvalid) { int errorCode = Marshal.GetLastWin32Error(); string message = WinApi.GetErrorMessage(errorCode); Debug.WriteLine($"System error {errorCode} ({message}) occurred on line {lineNumber} in file {filePath}"); } return(handle); }
private static SafeHandle getConsoleHandle(int nStdHandle) { IntPtr hConsole = NativeInterface.GetStdHandle(nStdHandle); SafeHandle handle = new ConsoleHandle(hConsole, true); if (handle.IsInvalid) { throw new Win32Exception(); } return(handle); }
/// <summary> /// Consctructor class for the buffer. Pass in the width and height you want the buffer to be. /// </summary> /// <param name="Width"></param> /// <param name="Height"></param> public buffer(int Width, int Height, int wWidth, int wHeight) // Create and fill in a multideminsional list with blank spaces. { if (Width > wWidth || Height > wHeight) { throw new System.ArgumentException("The buffer width and height can not be greater than the window width and height."); } h = GetStdHandle(STD_OUTPUT_HANDLE); width = Width; height = Height; windowWidth = wWidth; windowHeight = wHeight; buf = new CharInfo[width * height]; rect = new SmallRect(); rect.setDrawCord(0, 0); rect.setWindowSize((short)windowWidth, (short)windowHeight); Console.OutputEncoding = System.Text.Encoding.Unicode; Clear(); }
public static extern bool SetConsoleMode(ConsoleHandle hConsoleHandle, int dwMode);
public static extern bool ReadConsoleInput(ConsoleHandle hConsoleInput, ref INPUT_RECORD lpBuffer, uint nLenght, ref uint lpNumberOfEventsRead);
public static extern bool GetConsoleMode(ConsoleHandle hConsoleHandle, ref Int32 lpMode);
public static extern Boolean SetConsoleMode(ConsoleHandle hConsoleHandle, Int32 dwMode);
public static extern Boolean ReadConsoleInput(ConsoleHandle hConsoleInput, ref INPUT_RECORD lpBuffer, UInt32 nLength, ref UInt32 lpNumberOfEventsRead);
static extern bool WriteConsoleOutput( ConsoleHandle hConsoleOutput, CharInfo[] lpBuffer, Coord dwBufferSize, Coord dwBufferCoord, ref SmallRect lpWriteRegion);
public static extern Boolean GetNumberOfConsoleInputEvents(ConsoleHandle hConsoleInput, out UInt32 lpcNumberOfEvents);
public static extern bool GetNumberOfConsoleInputEvents(ConsoleHandle hConsoleInput, out uint lpcNumberOfEvents);
public static extern Boolean GetConsoleMode(ConsoleHandle hConsoleHandle, ref int lpMode);
public static void SetConsoleMode(ConsoleHandle bufferHandle, ConsoleMode mode) { if(bufferHandle == ConsoleHandle.OUTPUT) Extern.SetConsoleMode(consoleOutput, (byte)mode); if (bufferHandle == ConsoleHandle.INPUT) Extern.SetConsoleMode(consoleInput, (byte)mode); }
internal static extern Boolean GetConsoleMode(ConsoleHandle hConsoleHandle, ref Int32 lpMode);
private static SafeHandle getConsoleHandle(int nStdHandle) { IntPtr hConsole = NativeInterface.GetStdHandle(nStdHandle); SafeHandle handle = new ConsoleHandle(hConsole, true); if (handle.IsInvalid) { throw new Win32Exception(); } return handle; }