You use GetDC and ReleaseDC to obtain and release a handle to a device context.

Note also that in your WM_PAINT message, g_bFirstPass will always be true as it is always set to true before the...