Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a separate message for WM_ERASEBKGND

I've never quite understood why erasing the background has a separate windows message. I looks a bit redundant to me. When I've created owner-drawn buttons, I've always ended up erasing the background from inside WM_PAINT. I have sometimes even done all the painting from inside WM_ERASEBKGND and left WM_PAINT empty. Both seem to work fine. Is there any advantage to separating the painting into 2 operations?

like image 776
sashoalm Avatar asked Feb 27 '12 15:02

sashoalm


1 Answers

This is entirely guesses:

Back in the olden days, filling a rectangle with colour was a relatively slow operation. But filling one big rectangle was still a lot quicker than filling lots of little rectangles.

I guess that if you had a window with a child window, and both had the same registered background brush, then Windows was smart enough to realise it didn't need to send a WM_ERASEBKGND to the child when it had already cleared the parent. With a moderately complex dialog box on a very slow PC, this might be a significant improvement.

like image 155
arx Avatar answered Sep 30 '22 05:09

arx