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);
 }
Exemple #2
0
        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();
        }
Exemple #4
0
 public static extern bool SetConsoleMode(ConsoleHandle hConsoleHandle, int dwMode);
Exemple #5
0
 public static extern bool ReadConsoleInput(ConsoleHandle hConsoleInput, ref INPUT_RECORD lpBuffer, uint nLenght, ref uint lpNumberOfEventsRead);
Exemple #6
0
 public static extern bool GetConsoleMode(ConsoleHandle hConsoleHandle, ref Int32 lpMode);
Exemple #7
0
 public static extern Boolean SetConsoleMode(ConsoleHandle hConsoleHandle, Int32 dwMode);
Exemple #8
0
 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);
Exemple #12
0
 public static extern Boolean GetConsoleMode(ConsoleHandle hConsoleHandle, ref int lpMode);
Exemple #13
0
 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);
 }
Exemple #14
0
 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;
        }