3

I'm trying to create a borderless console window.
I was able to set the windowstyle to WS_POPUP, which removed the borders, but there were some glitches; Glitches..

It seems that there are some parts on the console window that didn't get redrawn, or something like that, but I've tried using InvalidateRect() on the whole window, and other redrawing functions, but they don't seem to work.
Someone suggested using SetWindowPos() (with SWP_FRAMECHANGED), but that doesn't do anything either.

I have been fiddling with this probelm for a while now, and am pretty sure it has something to do with the clientarea not drawing properly (don't quote me on this)

Also the bottom glitchy part will turn black/transparent when I first scroll down and then up, but the text in my program sometimes isn't shown under it, which to my knowledge would suggest that it has no background, so it has sort of a 'chameleon' effect.

Any ideas?

  • 2
    The console doesn't usually take well to that kind of thing. – chris Oct 20 '12 at 20:50
  • I can see that. But that doesn't really help me. –  Oct 20 '12 at 20:53
  • What do you want to get at last? – Maximus Oct 20 '12 at 21:46
  • I can't quite understand your question. –  Oct 20 '12 at 21:52
  • 1
    You task (creating a borderless console window) looks like exercise. No? I mean, what the reason of the question. – Maximus Oct 20 '12 at 21:55
  • Theres no real 'reason' to do it, other than me just liking the way a borderless window looks. I mean, I _could_ leave the window to its default looks, but I think it would be kind of interesting and nice to try something like this. –  Oct 20 '12 at 21:56
  • Go to the one of alternative consoles, [ConEmu](http://stackoverflow.com/a/10904494/1405560) for example, and don't try to change native windows terminal behavior. It's too internal. – Maximus Oct 20 '12 at 21:58
  • I don't want to.. :/ Also, if I'm going to share this program to other people, later on, they'll need to download ConEmu too, which would be pretty annoying for them. I'll just try to figure this out, and if I find that this is too difficult for me, then I'll just leave the borders on and continue making my program. –  Oct 20 '12 at 22:06
  • 2
    Are you sure, you need console window, rather than GUI? You may draw anything and use any window style of GUI window ;-) As for you question, if you really need console - try to use `SetWindowRgn` instead of manipulating wnd styles. – Maximus Oct 20 '12 at 22:14
  • Yeah, I know I can do it a lot easier with a GUI window, but I want to make this project happen in a console window. As for SetWindowRgn.. It seems like I might be able to remove the borders by creating a custom HRGN with CreateRectRgn. If I'm able to do this, I'll post an answer to my own question later on. Thanks. –  Oct 20 '12 at 22:24
  • 2
    Fighting the way Windows wants to work is usually more trouble than it's worth. – Mark Ransom Nov 15 '12 at 04:51
  • I know that, but if I wanted to do something else, then I guess I would. –  Nov 15 '12 at 04:54

1 Answers1

3

I finally figured it out. (Big thanks to Maximus)
I had to use SetWindowRgn(), just like he suggested.

The final code would look something like this:

HWND hWnd = GetConsoleWindow();
RECT rcScr, rcWnd, rcClient;

GetWindowRect(hWnd, &rcWnd);
GetWindowRect(GetDesktopWindow(), &rcScr);
GetClientRect(hWnd, &rcClient);

MoveWindow(hWnd, (rcScr.right / 2) - 330, (rcScr.bottom / 2) - 180, rcWnd.right - rcWnd.left, rcWnd.bottom - rcWnd.top, 1);
SetWindowLong(hWnd, GWL_STYLE, WS_POPUP);
SetWindowRgn(hWnd, CreateRectRgn(rcClient.left + 2, rcClient.top + 2, rcClient.right + 2, rcClient.bottom + 2), TRUE);
ShowWindow(hWnd, 1);
  • I found out that on recent version of Windows that sending only `ShowWindow()` will suffice to make the cmd correctly looking again. – Charles Milette Feb 07 '17 at 23:34
  • @charles.milette Based on my testing, that's only the case on Windows 10 with the new cmd.exe with "Use legacy console" left unchecked. I'd love to find a fix to this that wasn't just "clip the problem out of view". – comesuccingfuccslot Mar 09 '17 at 06:54