Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ SetWindowSize()

static unsafe void System.ConsolePal.SetWindowSize ( int width,
int height )
inlinestatic

Definition at line 893 of file ConsolePal.cs.

894 {
895 if (width <= 0)
896 {
897 throw new ArgumentOutOfRangeException("width", width, System.SR.ArgumentOutOfRange_NeedPosNum);
898 }
899 if (height <= 0)
900 {
901 throw new ArgumentOutOfRangeException("height", height, System.SR.ArgumentOutOfRange_NeedPosNum);
902 }
903 global::Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO bufferInfo = GetBufferInfo();
904 bool flag = false;
905 global::Interop.Kernel32.COORD size = default(global::Interop.Kernel32.COORD);
906 size.X = bufferInfo.dwSize.X;
907 size.Y = bufferInfo.dwSize.Y;
908 if (bufferInfo.dwSize.X < bufferInfo.srWindow.Left + width)
909 {
910 if (bufferInfo.srWindow.Left >= 32767 - width)
911 {
912 throw new ArgumentOutOfRangeException("width", System.SR.Format(System.SR.ArgumentOutOfRange_ConsoleWindowBufferSize, 32767 - width));
913 }
914 size.X = (short)(bufferInfo.srWindow.Left + width);
915 flag = true;
916 }
917 if (bufferInfo.dwSize.Y < bufferInfo.srWindow.Top + height)
918 {
919 if (bufferInfo.srWindow.Top >= 32767 - height)
920 {
921 throw new ArgumentOutOfRangeException("height", System.SR.Format(System.SR.ArgumentOutOfRange_ConsoleWindowBufferSize, 32767 - height));
922 }
923 size.Y = (short)(bufferInfo.srWindow.Top + height);
924 flag = true;
925 }
926 if (flag && !global::Interop.Kernel32.SetConsoleScreenBufferSize(OutputHandle, size))
927 {
929 }
930 global::Interop.Kernel32.SMALL_RECT srWindow = bufferInfo.srWindow;
931 srWindow.Bottom = (short)(srWindow.Top + height - 1);
932 srWindow.Right = (short)(srWindow.Left + width - 1);
933 if (!global::Interop.Kernel32.SetConsoleWindowInfo(OutputHandle, absolute: true, &srWindow))
934 {
935 int lastPInvokeError = Marshal.GetLastPInvokeError();
936 if (flag)
937 {
938 global::Interop.Kernel32.SetConsoleScreenBufferSize(OutputHandle, bufferInfo.dwSize);
939 }
940 global::Interop.Kernel32.COORD largestConsoleWindowSize = global::Interop.Kernel32.GetLargestConsoleWindowSize(OutputHandle);
941 if (width > largestConsoleWindowSize.X)
942 {
943 throw new ArgumentOutOfRangeException("width", width, System.SR.Format(System.SR.ArgumentOutOfRange_ConsoleWindowSize_Size, largestConsoleWindowSize.X));
944 }
945 if (height > largestConsoleWindowSize.Y)
946 {
947 throw new ArgumentOutOfRangeException("height", height, System.SR.Format(System.SR.ArgumentOutOfRange_ConsoleWindowSize_Size, largestConsoleWindowSize.Y));
948 }
949 throw System.IO.Win32Marshal.GetExceptionForWin32Error(lastPInvokeError);
950 }
951 }
static IntPtr OutputHandle
static global::Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO GetBufferInfo()
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static string ArgumentOutOfRange_NeedPosNum
Definition SR.cs:20
static string ArgumentOutOfRange_ConsoleWindowSize_Size
Definition SR.cs:16
static string ArgumentOutOfRange_ConsoleWindowBufferSize
Definition SR.cs:14
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7

References System.SR.ArgumentOutOfRange_ConsoleWindowBufferSize, System.SR.ArgumentOutOfRange_ConsoleWindowSize_Size, System.SR.ArgumentOutOfRange_NeedPosNum, System.SR.Format(), System.ConsolePal.GetBufferInfo(), System.IO.Win32Marshal.GetExceptionForWin32Error(), System.Runtime.InteropServices.Marshal.GetLastPInvokeError(), and System.ConsolePal.OutputHandle.

Referenced by System.Console.SetWindowSize().