Why there is a separate message for WM_ERASEBKGND

I never understood why there is a separate window when erasing the background. I look a little redundant to me. When I created the buttons created by the owner, I always ended up erasing the background from WM_PAINT. Sometimes I even did the whole picture from inside WM_ERASEBKGND and left WM_PAINT empty. Both seem to be working fine. Is there any advantage to dividing the picture into 2 operations?

+6
source share
1 answer

This is completely guesswork:

In the old days, filling a rectangle with color was relatively slow. But filling one large rectangle was much faster than filling a large number of small rectangles.

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

+4
source

Source: https://habr.com/ru/post/909455/


All Articles