Handmade Hero»Forums»Code
4 posts
Day 002 - Creating a Window
Edited by pikachuster on Reason: Update title.
I'm following along with the code given on Day 002, but I seem to be getting the weird repeating pattern shown in the image below. The larger white rectangle appeared when I opened the Windows 'Start Menu' and covered the aforementioned area. The squarish black area appeared when another window for a screen capture utility was put on top. Dragging the created window around results in even more severe corruption! Could somebody help me figure what's going on?

Please see imgur for what I mean.

Hardware: Quadro 2000M/Intel HD on Win 7 x64.
Mārtiņš Možeiko
2559 posts / 2 projects
Day 002 - Creating a Window
Edited by Mārtiņš Možeiko on
This is expected output. It happens because when OS asks your program to repaint are that was not visible before (for example it was covered by other window, or the application window was resized), it generates WM_PAINT message. Casey wrote WM_PAINT message handler in a way that it draws either black and white color interleaved. If in previous call it drew white color, then it now will draw black, and next time white again.

OS simply generates bunch of rectangles for your application to repaint (vai WM_PAINT message) and your application is painting them black and white.
4 posts
Day 002 - Creating a Window
Edited by pikachuster on Reason: Added link.
But on the live stream in the Visual Studio environment, the entire window changed between black and white when he resized it with the mouse. Perhaps, this is what I'm getting confused on. See around 59:30 of YouTube.
Mārtiņš Možeiko
2559 posts / 2 projects
Day 002 - Creating a Window
Edited by Mārtiņš Možeiko on
I'm not completely sure where is the difference, but it may be because Casey is not using Aero style in Windows 7, that means no compositor is running. I get exactly same behavior as you on my Windows 10 (where you cannot turn off compositor). Or it could be because OBS is running in background.

Day 2 code in WM_PAINT does painting only on rectangle that is passed in by OS. And OS can decide to pass whatever rectangles it wants. It can be full window size, or it can be two half-sizes. You cannot rely on specific behavior there.

If you want to see window to be fully repainted when it is resized, add HREDRAW and VREDRAW class styles, as documented here:
1
WindowClass.style=CS_HREDRAW|CS_VREDRAW;
4 posts
Day 002 - Creating a Window
Thanks for that really helpful reply! I'll investigate it and get back to the forum.
4 posts
Day 002 - Creating a Window
Edited by pikachuster on Reason: Corrected myself.
The issue is getting somewhat better after adding the code. The rapid changing between black and white now happens on half the screen. However, some boundary issues seems to be popping up. Initially, only about half the screen appears to be filled with WHITENESS. See imgur.

Edit: I've made a stupid boundary error, switching height and width. Knew it had to something simple.