zoukankan      html  css  js  c++  java
  • C# 控制台应用 禁止 快捷输入,关闭按钮 等等

    #region 设置控制台标题 禁用关闭按钮
    
            [DllImport("user32.dll", EntryPoint = "FindWindow")]
            extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
            [DllImport("user32.dll", EntryPoint = "GetSystemMenu")]
            extern static IntPtr GetSystemMenu(IntPtr hWnd, IntPtr bRevert);
            [DllImport("user32.dll", EntryPoint = "RemoveMenu")]
            extern static IntPtr RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);
    
            static void DisbleClosebtn()
            {
                IntPtr windowHandle = FindWindow(null, "控制台标题");
                IntPtr closeMenu = GetSystemMenu(windowHandle, IntPtr.Zero);
                uint SC_CLOSE = 0xF060;
                RemoveMenu(closeMenu, SC_CLOSE, 0x0);
            }
            protected static void CloseConsole(object sender, ConsoleCancelEventArgs e)
            {
                Environment.Exit(0);
            }
            #endregion



    #region 关闭控制台 快速编辑模式、插入模式
            const int STD_INPUT_HANDLE = -10;
            const uint ENABLE_QUICK_EDIT_MODE = 0x0040;
            const uint ENABLE_INSERT_MODE = 0x0020;
            [DllImport("kernel32.dll", SetLastError = true)]
            internal static extern IntPtr GetStdHandle(int hConsoleHandle);
            [DllImport("kernel32.dll", SetLastError = true)]
            internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint mode);
            [DllImport("kernel32.dll", SetLastError = true)]
            internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint mode);
    
            public static void DisbleQuickEditMode()
            {
                IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE);
                uint mode;
                GetConsoleMode(hStdin, out mode);
                mode &= ~ENABLE_QUICK_EDIT_MODE;//移除快速编辑模式
                mode &= ~ENABLE_INSERT_MODE;      //移除插入模式
                SetConsoleMode(hStdin, mode);
            }
            #endregion

    转载地址  https://www.cnblogs.com/gilbert/p/10262314.html

  • 相关阅读:
    快速排序 C语言实现
    怎样认识女孩?
    看了你就想结婚!)
    C语言面试题大汇总
    VC6.0下载地址
    STL vector 容器介绍
    Beauty of Maths! Amazing!
    自我参考:Java学习的30个目标
    Beauty of Maths! Amazing!
    采用 Java 持久化框架:选择、时机和优缺点?
  • 原文地址:https://www.cnblogs.com/xiongyang123/p/11059263.html
Copyright © 2011-2022 走看看