Windows 11 Gray out Maximize & Minimize Button

This is not a duplicate
Related (Working on windows 10, 7):

  • Disable Maximize Button c++ console application

New Problem:
After reading the coments the new problem seems to get the correct window to modify the menu because ‘GetConsoleWindow’ seems to not work.

In Windows 10 you were able to disable / gray out windows Minimize, Naximize and Close buttons but the same methods dont work on windows 11 if anyone has a new working mehtod / alternative or information if its even posible any hint would be apreciated.

Methods i have tryed:

  • DeleteMenu + GetConsoleWindow + GetSystemMenu
  • EnableMenuItem + GetConsoleWindow + GetSystemMenu
  • SetWindowLong + GetConsoleWindow

Mehods to update window i have tryed:

  • DrawMenu
  • SetWindowPos (SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED)

Expectet:

  • Grayed out Maximize, Minimize, Close Button / Disabled (not clickable)

Errors Encountered:

  • With FormatMessage and GetLastError i always get either no error or a Invalid Menu Handle Error

  • But no result both ways not visualy (grayed out) or interactivly (can still use buttons)

Resources i have used:

https://learn.microsoft.com/en-us/windows/console/getconsolewindow

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmenu

https://learn.microsoft.com/en-us/windows/console/getstdhandle

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablemenuitem

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlongptra

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-deletemenu

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawmenubar

EDIT Add Code (Minimal C# Console App to Disable Maximize, Minimize using Delete Menu Method):

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 ();

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool DrawMenuBar (IntPtr consoleWindow);

    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);
        DrawMenuBar(GetConsoleWindow());
        Console.Read();
    }

}

Code Example (Disable Maximize Button using SetWindowLong Method):

class Program
{
    // Importing necessary user32.dll functions
    [DllImport("kernel32.dll")]
    private static extern IntPtr GetConsoleWindow ();

    [DllImport("user32.dll")]
    private static extern long GetWindowLong (IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]
    private static extern int SetWindowLong (IntPtr hWnd, int nIndex, long dwNewLong);

    [DllImport("user32.dll")]
    private static extern bool SetWindowPos (IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

    // Constants for window styles
    const int GWL_STYLE = -16;
    const long WS_MAXIMIZEBOX = 0x00010000;
    const uint SWP_NOSIZE = 0x0001;
    const uint SWP_NOMOVE = 0x0002;
    const uint SWP_FRAMECHANGED = 0x0020;

    static void Main ()
    {
        IntPtr hwnd = GetConsoleWindow();

        long style = GetWindowLong(hwnd, GWL_STYLE);

        style &= unchecked(~WS_MAXIMIZEBOX);

        SetWindowLong(hwnd, GWL_STYLE, style);

        SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED);

        Console.WriteLine("Maximize box has been disabled.");
        Console.ReadLine();
    }
}

New contributor

FireDragon91245 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

10

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật