禁用C#控制台的最大化和最小化按钮 [英] Disable the maximize and minimize buttons of a c# console

查看:88
本文介绍了禁用C#控制台的最大化和最小化按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都是为了禁用c#应用程序的控制"栏.这非常类似于如何我在Visual Studio控制台应用程序中禁用了控制台窗口的关闭按钮?

I have looked around for disabling the 'control' bar of a c# application. It's very similar to how can i disable close button of console window in a visual studio console application?

但是,我也希望将其应用于最小化"和最大化"按钮.我不确定前面的解释中的代码是怎么回事,所以这可能是我将其应用于所有按钮的问题.

However I also wish to apply this to the minimize and maximize buttons. I'm not sure whats going on with the code from the previous explanation so that may be my issue in applying it to all the buttons.

推荐答案

这是一个解决方案:

 class Program
    {
        private const int MF_BYCOMMAND = 0x00000000;
        public const int SC_CLOSE = 0xF060;
        public const int SC_MINIMIZE = 0xF020;
        public const int SC_MAXIMIZE = 0xF030;

        [DllImport("user32.dll")]
        public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);

        [DllImport("user32.dll")]
        private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

        [DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern IntPtr GetConsoleWindow();

        static void Main(string[] args)
        {
            DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_CLOSE, MF_BYCOMMAND);
            DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_MINIMIZE, MF_BYCOMMAND);
            DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_MAXIMIZE, MF_BYCOMMAND);
            Console.Read();
        }

    }

这篇关于禁用C#控制台的最大化和最小化按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆