我一直在寻找禁用ac#应用程序的"控制"栏.它与如何在visual studio控制台应用程序中禁用控制台窗口的关闭按钮非常相似 ?
但是我也希望将它应用于最小化和最大化按钮.我不确定是否继续使用前面解释中的代码,因此将其应用于所有按钮可能是我的问题.
这是一个解决方案:
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();
}
}
Run Code Online (Sandbox Code Playgroud)