3
votes

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?

1
The console doesn't usually take well to that kind of thing.chris
I can see that. But that doesn't really help me.user1219742
You task (creating a borderless console window) looks like exercise. No? I mean, what the reason of the question.Maximus
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
Fighting the way Windows wants to work is usually more trouble than it's worth.Mark Ransom

1 Answers

3
votes

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);