miles_williams
what I don't quite understand is exactly how the switch clause in Win32MainWindowCallback() manages to get a hold of these messages? ...
Does DispatchMessage() look into our WNDCLASS structure and find that lpfnWndProc has been set to point to our Win32MainWindowCallback() function? And does the DispatchMessage() function call into it passing the message?
This is exactly how it works, yes.
Because Windows is Windows, and doesn't like to bother with things like being consistent, technically there are
two distinct ways this dispatch occurs. The first is exactly how you surmised - when we call DispatchMessage(), Windows will (eventually) use the HWND in the message structure to look up the class of the window, and then look up in the class what the message handler function is, and then finally jump to it with the contents of the MSG passed as parameters. It sounds like you already were guessing that.
The second way it can happen is that certain parts of Windows will simply call your lpfnWndProc directly without ever posting the message. This happens when a piece of Windows decides it wants to synchronously ask you to do something, and wants the result immediately, and doesn't want to put it in a queue to be processed in line with everything else. The process is still just like DispatchMessage() in that it looks up the lpfnWndProc in the WNDCLASS, but it just never goes through the MSG queue.
miles_williams
Are we filling up a huge region of memory with ALL the values required to write a WHOLE window full of pixels' individual RGB values and then writing them all to the screen with Win32UpdateWindow() and StretchDIBits() and then once everything is written to the screen we ReleaseDC() and increment offsets and go back through the nested loops and all that jazz all over again, over and over?
Yep, we sure are.
miles_williams
And in this process do our offsets keep growing to the max size of an int before wrapping but because they are being added to the X and Y values inside RenderWeirdGradient() and assigned to uint8_t variables (Blue and Green) they wrap after reaching 255? What happens when the offsets reach the maximum int value and wrap around? Wont that cause some problem? Or will it just align and when the ints wrap the uint_t's will wrap at the same time with both becoming zero and starting all over again? If for instance we were incrementing the YOffset by a number that the maximum int value was not divisible by would we have an issue of not wrapping around to zero in sync with our Green value?
Going to have to admit that at this point I have long forgotten what we were doing in RenderWeirdGradient() :) But generally speaking yes, if you were to look at the bottom 8 bits of a 32-bit value (the low-order uint8_t of a uint32_t), they're not affected by the _upper_ part of the value during addition, if that makes sense. So adding to an 8-bit value and adding to a 32-bit value is generally the same effect if all you're doing is adding!
- Casey