1

I want my console window to be modified. I got the handle. And this helps to change it. But how can I

  • remove close button
  • remove maximize button
  • remove icon
  • disable resizing

?

// C# syntax
StringBuilder buffer = new StringBuilder(260);
IntPtr window = FindWindow(null, buffer.ToString(0, GetConsoleTitle(buffer, buffer.Capacity)));

uint a = (uint)((WS_BORDER | WS_CAPTION) & (~WS_ICONIC));
SetWindowLongPtr(window, -16, new IntPtr(a)); // GWL_STYLE = -16

For some reason the window is broken after this call. I can't move it with the mouse anymore and all clicks go through it to other windows.

Community
  • 1
  • 1
Bitterblue
  • 13,162
  • 17
  • 86
  • 124

1 Answers1

2

You removed all the window styles, and added back just WS_BORDER and WS_CAPTION. What you should do is:

  1. Read the current window style with a call to GetWindowLongPtr.
  2. Perform bitwise AND with the bitwise negation of the styles you want to remove.
  3. Set the window style with a call to SetWindowLongPtr.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490