Created
August 31, 2020 21:44
-
-
Save FeniXb3/bcf410fe3d6d19d36c34fc434492b2da to your computer and use it in GitHub Desktop.
C# code for disabling minimizing, maximizing and resizing of console Window. Works on Windows, didn't check other systems.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Code based on: | |
https://stackoverflow.com/a/34199784/1816426 | |
https://stackoverflow.com/a/38175919/1816426 | |
*/ | |
class Program | |
{ | |
// Documentation: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-deletemenu | |
private const int MF_BYCOMMAND = 0x00000000; | |
// Documentation: https://docs.microsoft.com/en-us/windows/win32/menurc/wm-syscommand | |
public const int SC_SIZE = 0xF000; | |
public const int SC_MINIMIZE = 0xF020; | |
public const int SC_MAXIMIZE = 0xF030; | |
// Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportattribute?view=netcore-3.1 | |
[DllImport("user32.dll")] | |
// Documentation: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-deletemenu | |
public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags); | |
[DllImport("user32.dll")] | |
// Documentation: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmenu | |
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); | |
[DllImport("kernel32.dll", ExactSpelling = true)] | |
// Documentation: https://docs.microsoft.com/en-us/windows/console/getconsolewindow | |
private static extern IntPtr GetConsoleWindow(); | |
static void Main(string[] args) | |
{ | |
DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_SIZE, MF_BYCOMMAND); // Disable resizing | |
DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_MINIMIZE, MF_BYCOMMAND); // Disable minimizing | |
DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_MAXIMIZE, MF_BYCOMMAND); // Disable maximizing | |
Console.ReadKey(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment