Exemplo n.º 1
0
        /// <summary>
        /// 弹出消息框
        /// </summary>
        /// <param name="text">消息框文本</param>
        /// <param name="caption">消息框标题</param>
        /// <param name="messageBoxType">消息框类型</param>
        /// <param name="messageBoxIcon">消息框图标</param>
        /// <param name="messageBoxDefault">消息框默认选项</param>
        /// <returns>用户选择</returns>
        public static MessageBoxChoice MessageBox(string text, string caption, MessageBoxType messageBoxType, MessageBoxIcon messageBoxIcon, MessageBoxDefault messageBoxDefault)
        {
            uint type = (uint)messageBoxType | (uint)messageBoxIcon | (uint)messageBoxDefault;

            Error.Check(KERNEL.MESSAGE_BOX(text, caption, type, out int choose));
            return((MessageBoxChoice)choose);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 使控制台窗口在桌面上居中显示
        /// </summary>
        public static void CenterConsoleWindowPosition()
        {
            Error.Check(KERNEL.GET_DESKTOP_SIZE(out int desktopWidth, out int desktopHeight));
            Error.Check(KERNEL.GET_WINDOW_SIZE(out int windowWidth, out int windowHeight));

            int x = (desktopWidth / 2) - (windowWidth / 2);
            int y = (desktopHeight / 2) - (windowHeight / 2);

            Error.Check(KERNEL.SET_WINDOW_POS(x, y));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取控制台字体
        /// </summary>
        /// <param name="consoleOutputHandle">控制台标准输出句柄</param>
        /// <param name="bold">是否使用粗体</param>
        /// <param name="fontWidth">字体宽度</param>
        /// <param name="fontHeight">字体高度</param>
        /// <param name="fontName">字体名字</param>
        public static void GetConsoleFont(IntPtr consoleOutputHandle, out bool bold, out short fontWidth, out short fontHeight, out string fontName)
        {
            byte[] bytes = new byte[FACE_SIZE * SIZE_OF_WCHAR];

            Error.Check(KERNEL.GET_CONSOLE_FONT(consoleOutputHandle, out bold,
                                                out fontWidth, out fontHeight, ref bytes[0]));

            string str = Encoding.Unicode.GetString(bytes);

            string[] strArray = str.Split('\0');
            fontName = strArray[0];
        }
Exemplo n.º 4
0
 /// <summary>
 /// 设置标准控制台调色盘
 /// </summary>
 /// <param name="consoleOutputHandle">控制台标准输出句柄</param>
 /// <param name="paletteType">调色盘类型</param>
 public static void SetStdConsolePalette(IntPtr consoleOutputHandle, PaletteType paletteType = PaletteType.Modern)
 {
     if (paletteType == PaletteType.Legacy)
     {
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 0, 0, 0, 0));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 1, 0, 0, 128));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 2, 0, 128, 0));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 3, 0, 128, 128));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 4, 128, 0, 0));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 5, 128, 0, 128));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 6, 128, 128, 0));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 7, 192, 192, 192));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 8, 128, 128, 128));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 9, 0, 0, 255));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 10, 0, 255, 0));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 11, 0, 255, 255));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 12, 255, 0, 0));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 13, 255, 0, 255));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 14, 255, 255, 0));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 15, 255, 255, 255));
     }
     if (paletteType == PaletteType.Modern)
     {
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 0, 12, 12, 12));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 1, 0, 55, 218));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 2, 19, 161, 14));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 3, 58, 150, 221));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 4, 197, 15, 31));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 5, 136, 23, 152));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 6, 193, 156, 0));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 7, 204, 204, 204));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 8, 118, 118, 118));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 9, 59, 120, 255));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 10, 22, 198, 12));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 11, 97, 214, 214));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 12, 231, 72, 86));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 13, 180, 0, 158));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 14, 249, 241, 165));
         Error.Check(KERNEL.SET_CONSOLE_PALETTE(consoleOutputHandle, 15, 242, 242, 242));
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 设置标准控制台模式
 /// </summary>
 /// <param name="consoleOutputHandle">控制台标准输出句柄</param>
 /// <param name="consoleInputHandle">控制台标准输入句柄</param>
 public static void SetStdConsoleMode(IntPtr consoleOutputHandle, IntPtr consoleInputHandle)
 {
     Error.Check(KERNEL.GET_CONSOLE_MODE
                 (
                     consoleOutputHandle,
                     consoleInputHandle,
                     out ConsoleInputMode consoleInputMode,
                     out ConsoleOutputMode consoleOutputMode
                 ));
     //允许窗口输入
     consoleInputMode.EnableWindowInput = true;
     //关闭快速编辑模式
     consoleInputMode.EnableQuickEditMode = false;
     Error.Check(KERNEL.SET_CONSOLE_MODE
                 (
                     consoleOutputHandle,
                     consoleInputHandle,
                     consoleInputMode,
                     consoleOutputMode
                 ));
 }
Exemplo n.º 6
0
 /// <summary>
 /// 设置控制台字体
 /// </summary>
 /// <param name="consoleOutputHandle">控制台标准输出句柄</param>
 /// <param name="bold">是否使用粗体</param>
 /// <param name="fontWidth">字体宽度</param>
 /// <param name="fontHeight">字体高度</param>
 /// <param name="fontName">字体名字</param>
 public static void SetConsoleFont(IntPtr consoleOutputHandle, bool bold, short fontWidth, short fontHeight, string fontName)
 {
     Error.Check(KERNEL.SET_CONSOLE_FONT(consoleOutputHandle, bold, fontWidth, fontHeight,
                                         fontName, (uint)fontName.Length));
 }
Exemplo n.º 7
0
 /// <summary>
 /// 获取按键输入
 /// </summary>
 /// <param name="consoleKey">控制台按键</param>
 /// <returns>是否按下</returns>
 public static bool GetKey(ConsoleKey consoleKey)
 {
     return(KERNEL.GET_KEY((int)consoleKey));
 }