Handmade Hero Day 002 with QA

Driving through with mental grit

What did we cover today. 

In Day 002 Casey covers how to get an "real" window on the Windows platform. We pick off were we left off on day one were we were outputting a single MessageBox to the user without a window. In today's stream we learn how to use the win32 api to create a basic window. A very basic window as this window does not even allow us to close the screen. Casey has said that we will be covering that in the next stream so that is something to look forward to. 

 Any gotchas for me along the way

After the stream I started to play around a little to see if with the current knowledge from the stream I could create a rectangle that keep re-sizing as the screen size changed. I attempted at first to hook into the WM_SIZE message and add and additional HDC context with BeginPaint. After some trial and error I realized this would not work as the context was the same for both paints because it is, I believe tied to the window handle passed in. At least that is what the debugger seems to indicate as the memory address is the same.

 

 

After flailing around for a bit with various other means I started to look into where  you create the WNDCLASSA struct. The documentation states that the hbrBackground is of type HBRUSH. If you provide a valid HBRUSH then windows will automatically update the background. After looking into how to create a HBRUSH with some RGB values I was able to get it to work kind of. I will show you in a small screen cast below how the rectangle with in the window behaves on resizing.


 As you can see the screen correctly updates the image during the WM_SIZE message. You can see my full struggle in the YouTube cast below and I have even pinpointed where my frustration was lying in the output. Its nice to fail sometimes as that helps you realize maybe were you went wrong and what needs to change to move forward.


 

Any tips I would like to share

I think that the struggle is real right now for me. I would say a tip I have is to continue to stick through it if it is hard and make sure you get a small success everyday. 

I think for me coming from a heavy high(er) level language and object oriented background I am over complicating things. I have not training my brain to expect that something as simple as creating a HBRUSH would allow me to solve my issue. I am usually looking for a class or component that has beep initialization and complex wiring. I need to start thinking a little simpler maybe.  

Reflection on progress thus far. 

As I said above its starting to get hard but its also cool to have even done that. I am not sure I could have done that as easily in C# on any modern desktop sdk and definitely with not such low memory footprint. This is fun looking forward to day 3. 

Comments