I have created a program that – among other things – changes the console window size and removes the window borders from it (mostly by setting the window style to WS_POPUP).
Now on my computer, the application is executed with no problems whatsoever, but when I run the code in another computer (or in VirtualBox), I get some funky glitches.
Here’s an image that shows these glitches I speak of:

These glitches appearead if the user moved/opened a window on top of the console window and then brought the console window to the top again.
So naturally, I thought that the easiest way to get rid of this problem would be to make the console window always on top, but that didn’t help, because now the glitches just take their ‘background’ from whatever was there before the new window was moved/opened on top (or rather, below) the console window.
It seems that the glitched areas are somehow cached/stored somewhere, and do not notice that the window has been resized.
GetClientRect(hWnd, &rClnt);
rClnt.top += 1;
rClnt.bottom -= 2;
rClnt.right -= 1;
SetWindowRgn(hWnd, CreateRectRgnIndirect(&rClnt), 1);
SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP);
exStyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE);
exStyle &= ~WS_EX_CLIENTEDGE;
SetWindowLongPtr(hWnd, GWL_EXSTYLE, exStyle);
BringWindowToTop(hWnd);
SetWindowPos(hWnd, HWND_TOPMOST, ((rScr.right / 2) - rWnd.right / 2) - 1, (rScr.bottom / 2) - rWnd.bottom / 2, 0, 0, SWP_FRAMECHANGED | SWP_DRAWFRAME | SWP_NOSIZE);// After this I just use ShowWindow().
I managed to fix the glitches.
All I did was I moved the
SetWindowRgn()function just above theShowWindow()(which would be at the very end of the code snippet).This removed the glitched areas, and now my window displays correctly.
There was a bug where the window was not centered afterwards, but I fixed it by changing
to