找传奇、传世资源到传世资源站!

禁用控制台右上角关闭功能

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboardusing 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); } } }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复