user1219742
user1219742

Reputation:

C++: Setting the console window as a WS_POPUP

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?

Upvotes: 3

Views: 2511

Answers (1)

user1219742
user1219742

Reputation:

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

Upvotes: 3

Related Questions