Handmade Hero»Forums»Code
rs
R
1 posts
WM_PAINT Question (Beginner)
Hi,

I just discovered Handmade Hero and watched the first 6 episodes. Not sure if this question has been answered but here it is:

So we are using the function Win32DisplayBufferInWindow in both the while(running) loop and in the WM_PAINT window callback. Why does it have to be in both places?

My understanding (from MSDN) is that WM_PAINT is returned when the message queue is empty and as a result will call the Win32DisplaybufferInWindow function. Why do we need it also in the while(running) loop. Or since we have it in the while loop why do we need it in the WM_PAINT switch?
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
WM_PAINT Question (Beginner)
Actually, WM_PAINT is called any time Windows thinks it wants you to repaint your window. So, for example, it might call it when the window is moved or resized, depending on the window class settings. So we don't need to call Win32DisplayBufferInWindow in WM_PAINT for _our_ frame updates, but we do need to call it there if _windows_ wants to repaint the window - say, when the user drags the window around the screen, etc.

- Casey