Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-05

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

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

cobines

Hello.

The WMEraseBkgnd handler is implemented as:

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

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 structure."

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

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).

cobines

Reply by email