Bitterblue
Bitterblue

Reputation: 14085

WinApi - How To Modify Console Window?

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

?

// 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.

Upvotes: 1

Views: 285

Answers (1)

David Heffernan
David Heffernan

Reputation: 613451

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.

Upvotes: 2

Related Questions