[Lazarus] TWinControl.WMEraseBkgnd - should it always set Message.Result := 1

cobines cobines at gmail.com
Tue May 15 19:06:02 CEST 2012


The WMEraseBkgnd handler is implemented as:

procedure TWinControl.WMEraseBkgnd(var Message: TLMEraseBkgnd);
  if (Message.DC <> 0) and (wcfEraseBackground in FWinControlFlags) then
    Message.Result := 1;

On Windows, if it does not set Result to 1 then, as it says in MSDN:

"The DefWindowProc function erases the background by using the class
background brush specified by the hbrBackground member of the WNDCLASS

So, the background is painted anyway but it may be painted with a
wrong color, because hbrBackground might be different than

This sometimes causes flickering because multiple WM_ERASEBKGND
messages are received during repainting but LCL does not accept some
of them and first Windows repaints background with hbrBackground and
then LCL repaints background with Brush.Color.

Putting Windows aside, from LCL points of view, what should happen if
WM_ERASEBKGND comes in but wcfEraseBackground is not in Flags? Does it
mean background should not be repainted? Or it just should not be
repainted by LCL but can be by the widgetset?

I don't know this is LCL problem (don't allow painting with
hbrBackground of window class) or LCLWin32 problem (set hbrBackground
to NULL for example).


More information about the Lazarus mailing list