前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[C#] 禁用控制台关闭按钮

[C#] 禁用控制台关闭按钮

作者头像
科控物联
发布2022-03-29 15:18:20
1.8K0
发布2022-03-29 15:18:20
举报
文章被收录于专栏:科控自动化

禁用控制台关闭按钮

internal class Program

{

[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>

static void closebtn()

{

IntPtr windowHandle = FindWindow(null, "AutoTecon数采系统");//名称要一致

IntPtr closeMenu = GetSystemMenu(windowHandle, IntPtr.Zero);

uint SC_CLOSE = 0xF060;

RemoveMenu(closeMenu, SC_CLOSE, 0x0);

}

static void Main(string[] args)

{

Console.Title = "AutoTecon数采系统";

closebtn();

Console.CancelKeyPress += new ConsoleCancelEventHandler(CloseConsole);

Console.WriteLine("Starting...");

Console.WriteLine("退出请按 Ctrl+C ");

/// <summary>

/// 关闭时的事件

/// </summary>

/// <param name="sender">对象</param>

/// <param name="e">参数</param>

static void CloseConsole(object sender, ConsoleCancelEventArgs e)

{

Environment.Exit(0);

//return;

}

}

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-09-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 科控物联 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档