C ++: console window has strange borders ..?

I created a program that, by the way, resizes the console window and removes the window borders from it (basically, setting the window style of WS_POPUP).
Now the application runs on my computer without any problems, but when I run the code on another computer (or in VirtualBox), I get some funky crashes.

Here is an image that shows these glitches that I'm talking about: glitches with awesome depth of field

These glitches appear if the user has moved / opened the window on top of the console window, and then again returned the console window to the top.
Naturally, I thought that the easiest way to get rid of this problem is to make the console window always on top, but this did not help, because now the glitches just take their β€œbackground” from what was there before the new window was moved / opened from above (or rather below) in the console window.
It seems that the glitches 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(). 
+4
source share
1 answer

I managed to fix glitches.

All I did was move the SetWindowRgn() function just above ShowWindow() (which would be at the very end of the code snippet).
This removed the bad areas and now my window displays correctly.


There was an error after which the window was not then centered, but I fixed it by changing

 if(!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)) 

to

 if(!SetWindowPos(hWnd, HWND_TOPMOST, ((rScr.right / 2) - rClnt.right / 2) - 1, (rScr.bottom / 2) - rClnt.bottom / 2, 0, 0, SWP_FRAMECHANGED | SWP_DRAWFRAME | SWP_NOSIZE)) 
0
source

All Articles