Originally Posted by
megafiddle
Could it be that the handle for DC_BRUSH is zero, and hBrush was also zero?
No DC_BRUSH can not be zero AND valid.
HBRUSH is a HANDLE or pointer (memory address) so can not be NULL and valid.
In DEBUG mode (as opposed to Release mode build) the hBrush is probably initialised to NULL by the IDE.
FillRect() would call SelectObject() and probably is coded not to allow a NULL GDI object to be selected into a DC (as then the DC would throw errors when it tried to use the non existent GDI object).
Code:
//why is the PAINTSTUCT static?
HDC hdcPaint = BeginPaint(hWnd, &ps);
FillRect(hDc, &ps.rcPaint, hBrush);
//should be
FillRect(ps.hdc, &ps.rcPaint, GetStockObject(WHITE_BRUSH));
// or
FillRect(hdcPaint , &ps.rcPaint, GetStockObject(WHITE_BRUSH));
EndPaint(hWnd, &ps);
//then there is no need to create or clean up any GDI objects
BUT!
Other events generate WM_PAINT msgs (ie another window crossing yours) with differing invalidated rects in the PAINTSTRUCT so your code will not always draw the way you expect.