Пример #1
0
        public void ScrollBuffer(int lines)
        {
            var handle = NativeMethods.GetStdHandle((uint)StandardHandleId.Output);

            var scrollRectangle = new SMALL_RECT
            {
                Top    = (short)lines,
                Left   = 0,
                Bottom = (short)(Console.BufferHeight - 1),
                Right  = (short)Console.BufferWidth
            };
            var destinationOrigin = new COORD {
                X = 0, Y = 0
            };
            var fillChar = new CHAR_INFO(' ', Console.ForegroundColor, Console.BackgroundColor);

            NativeMethods.ScrollConsoleScreenBuffer(handle, ref scrollRectangle, IntPtr.Zero, destinationOrigin, ref fillChar);
        }
Пример #2
0
        public void WriteBufferLines(BufferChar[] buffer, ref int top, bool ensureBottomLineVisible)
        {
            int bufferWidth     = Console.BufferWidth;
            int bufferLineCount = buffer.Length / bufferWidth;

            if ((top + bufferLineCount) > Console.BufferHeight)
            {
                var scrollCount = (top + bufferLineCount) - Console.BufferHeight;
                ScrollBuffer(scrollCount);
                top -= scrollCount;
            }

            var handle     = NativeMethods.GetStdHandle((uint)StandardHandleId.Output);
            var bufferSize = new COORD
            {
                X = (short)bufferWidth,
                Y = (short)bufferLineCount
            };
            var bufferCoord = new COORD {
                X = 0, Y = 0
            };
            var bottom      = top + bufferLineCount - 1;
            var writeRegion = new SMALL_RECT
            {
                Top    = (short)top,
                Left   = 0,
                Bottom = (short)bottom,
                Right  = (short)(bufferWidth - 1)
            };

            NativeMethods.WriteConsoleOutput(handle, ToCharInfoBuffer(buffer),
                                             bufferSize, bufferCoord, ref writeRegion);

            // Now make sure the bottom line is visible
            if (ensureBottomLineVisible &&
                (bottom >= (Console.WindowTop + Console.WindowHeight)))
            {
                Console.CursorTop = bottom;
            }
        }
Пример #3
0
        public CHAR_INFO[] ReadBufferLines(int top, int count)
        {
            var result = new CHAR_INFO[BufferWidth * count];
            var handle = NativeMethods.GetStdHandle((uint)StandardHandleId.Output);

            var readBufferSize = new COORD {
                X = (short)BufferWidth,
                Y = (short)count
            };
            var readBufferCoord = new COORD {
                X = 0, Y = 0
            };
            var readRegion = new SMALL_RECT
            {
                Top    = (short)top,
                Left   = 0,
                Bottom = (short)(top + count),
                Right  = (short)(BufferWidth - 1)
            };

            NativeMethods.ReadConsoleOutput(handle, result,
                                            readBufferSize, readBufferCoord, ref readRegion);
            return(result);
        }
Пример #4
0
 public static extern bool ReadConsoleOutput(IntPtr consoleOutput, [Out] CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion);
Пример #5
0
 public static extern bool WriteConsoleOutput(IntPtr consoleOutput, CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
Пример #6
0
 public static extern bool ScrollConsoleScreenBuffer(IntPtr hConsoleOutput,
                                                     ref SMALL_RECT lpScrollRectangle,
                                                     IntPtr lpClipRectangle,
                                                     COORD dwDestinationOrigin,
                                                     ref CHAR_INFO lpFill);
Пример #7
0
 public static extern bool ReadConsoleOutput(IntPtr consoleOutput, [Out] CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion);
Пример #8
0
        public CHAR_INFO[] ReadBufferLines(int top, int count)
        {
            var result = new CHAR_INFO[BufferWidth * count];
            var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output);

            var readBufferSize = new COORD {
                X = (short)BufferWidth,
                Y = (short)count};
            var readBufferCoord = new COORD {X = 0, Y = 0};
            var readRegion = new SMALL_RECT
            {
                Top = (short)top,
                Left = 0,
                Bottom = (short)(top + count),
                Right = (short)(BufferWidth - 1)
            };
            NativeMethods.ReadConsoleOutput(handle, result,
                readBufferSize, readBufferCoord, ref readRegion);
            return result;
        }
Пример #9
0
 public static extern bool WriteConsoleOutput(IntPtr consoleOutput, CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
Пример #10
0
        public void ScrollBuffer(int lines)
        {
            var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output);

            var scrollRectangle = new SMALL_RECT
            {
                Top = (short) lines,
                Left = 0,
                Bottom = (short)(Console.BufferHeight - 1),
                Right = (short)Console.BufferWidth
            };
            var destinationOrigin = new COORD {X = 0, Y = 0};
            var fillChar = new CHAR_INFO(' ', Console.ForegroundColor, Console.BackgroundColor);
            NativeMethods.ScrollConsoleScreenBuffer(handle, ref scrollRectangle, IntPtr.Zero, destinationOrigin, ref fillChar);
        }
Пример #11
0
        public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomLineVisible)
        {
            var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output);

            int bufferWidth = Console.BufferWidth;
            int bufferLineCount = buffer.Length / bufferWidth;
            if ((top + bufferLineCount) > Console.BufferHeight)
            {
                var scrollCount = (top + bufferLineCount) - Console.BufferHeight;
                ScrollBuffer(scrollCount);
                top -= scrollCount;
            }
            var bufferSize = new COORD
            {
                X = (short) bufferWidth,
                Y = (short) bufferLineCount
            };
            var bufferCoord = new COORD {X = 0, Y = 0};
            var bottom = top + bufferLineCount - 1;
            var writeRegion = new SMALL_RECT
            {
                Top = (short) top,
                Left = 0,
                Bottom = (short) bottom,
                Right = (short) (bufferWidth - 1)
            };
            NativeMethods.WriteConsoleOutput(handle, buffer,
                                             bufferSize, bufferCoord, ref writeRegion);

            // Now make sure the bottom line is visible
            if (ensureBottomLineVisible &&
                (bottom >= (Console.WindowTop + Console.WindowHeight)))
            {
                Console.CursorTop = bottom;
            }
        }
Пример #12
0
 public static extern bool ScrollConsoleScreenBuffer(IntPtr hConsoleOutput,
     ref SMALL_RECT lpScrollRectangle,
     IntPtr lpClipRectangle,
     COORD dwDestinationOrigin,
     ref CHAR_INFO lpFill);