I believe that it is more correct to set hbrBackground = GetStockObject(HOLLOW_BRUSH)
than it is to set it to NULL
.
An article on Raymond Chen's The Old New Thing makes a distinction:
If you don't want automatic background drawing, then pass the hollow brush. If you want custom background drawing, then pass NULL
as the brush.
The MSDN documentation for WNDCLASS
's hbrBackground
member says:
When this member is NULL
, an application must paint its own background whenever it is requested to paint in its client area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND
message or test the fErase
member of the PAINTSTRUCT
structure filled by the BeginPaint
function.
And the MSDN documentation for WM_ERASEBKGND
says:
The DefWindowProc
function erases the background by using the class background brush specified by the hbrBackground
member of the WNDCLASS
structure. If hbrBackground
is NULL
, the application should process the WM_ERASEBKGND
message and erase the background.
My interpretation is that setting hbrBackground
to NULL
and then neglecting to handle WM_ERASEBKGND
not meant to be strictly legal (but probably works); hbrBackground = NULL
is a promise that you will handle WM_ERASEBKGND
yourself and not let DefWindowProc
try to paint with a null pointer.