Is there a better way to remove all of the three buttons on the title-bar and remove the scroll-bar using Windows API?

浪子不回头ぞ 提交于 2019-12-03 20:28:30

You can try this:

#define WINVER 0x0501 // WinXP and UP
#include <windows.h>

int main ( void ) 
{
  LONG style;
  HWND ConsoleWindow;

  ConsoleWindow = GetConsoleWindow();

  style = GetWindowLong(ConsoleWindow, GWL_STYLE); 
  style &= ~( WS_MINIMIZEBOX | WS_SYSMENU ); 
  SetWindowLongPtr(ConsoleWindow, GWL_STYLE, style);

  SetWindowPos(ConsoleWindow, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED |
  SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);

  system ("pause>nul");
  return 0;
}

all buttons will be removed:

I found This after my comment saying I thought it was not possible...

void ClearButtons(void)
{
    int index = WS_BORDER;
    unsigned int a = (unsigned int)((WS_BORDER | WS_CAPTION) & (~WS_ICONIC));

    LONG_PTR lPtr;
    HWND hWnd = GetActiveWindow();
    lPtr = GetWindowLongPtr(hWnd, index); 
    SetWindowLongPtr(hWnd, GWL_STYLE, a);  
}

Note: When compiling for 32-bit Windows, SetWindowLongPtr is defined as a call to the SetWindowLong function. So, should work with either Windows 7, or with XP (did not test)

Test image:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!