基本信息
源码名称:禁用控制台右上角关闭功能
源码大小:0.04M
文件格式:.rar
开发语言:C#
更新时间:2019-01-15
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace 控制台禁用右上角关闭按钮
{
    class Program
    {
        static void Main(string[] args)
        {
                 Console.Title = "禁用右上角关闭功能";
                 closebtn(); 
                 Console.CancelKeyPress  = new ConsoleCancelEventHandler(CloseConsole);
                 Console.WriteLine("测试系统启动...");
                 Console.WriteLine("退出请按 Ctrl C ");
                 Console.Read();
        }
        [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);
        /// <summary>
        /// 禁用关闭按钮
        /// </summary>
       protected static void CloseConsole(object sender, ConsoleCancelEventArgs e)
      {
        Environment.Exit(0);//提供给操作系统的退出代码。使用 0(零)指示处理已成功完成
       }
    static void closebtn()
        {
            IntPtr windowHandle = FindWindow(null, "禁用右上角关闭功能");
            IntPtr closeMenu = GetSystemMenu(windowHandle, IntPtr.Zero);
            uint SC_CLOSE = 0xF060;//系统菜单命令Id
            RemoveMenu(closeMenu, SC_CLOSE, 0x0);
        }
    }


  
}