How to change console window style at runtime?

2019-07-30 15:53发布

问题:

I'm making a game in console application and I want to prevent user resizing and maximizing window. How can I do this using HWND?

回答1:

I found solution. This code will disable window Size and Maximize box:

HWND consoleWindow = GetConsoleWindow();
SetWindowLong(consoleWindow, GWL_STYLE, GetWindowLong(consoleWindow, GWL_STYLE) & ~WS_MAXIMIZEBOX & ~WS_SIZEBOX);