Register
pikachuster
5 posts
#10346 Day 002 - Creating a Window
Jan. 11, 2017, 11:40 p.m. Edited by on Jan. 11, 2017, 11:47 p.m. 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.
mmozeiko
Mārtiņš Možeiko
1131 posts
1 project
#10349 Day 001/002 - Creating a Window
Jan. 11, 2017, 11:54 p.m. Edited by Mārtiņš Možeiko on Jan. 11, 2017, 11:55 p.m.

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.
pikachuster
5 posts
#10350 Day 001/002 - Creating a Window
Jan. 11, 2017, 11:57 p.m. Edited by on Jan. 12, 2017, midnight 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.
mmozeiko
Mārtiņš Možeiko
1131 posts
1 project
#10351 Day 002 - Creating a Window
Jan. 12, 2017, 12:42 a.m. Edited by Mārtiņš Možeiko on Jan. 12, 2017, 12:50 a.m.

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;
pikachuster
5 posts
#10354 Day 002 - Creating a Window
Jan. 12, 2017, 2:20 a.m.

Thanks for that really helpful reply! I'll investigate it and get back to the forum.
pikachuster
5 posts
#10355 Day 002 - Creating a Window
Jan. 12, 2017, 4:30 a.m. Edited by on Jan. 12, 2017, 4:38 a.m. 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.