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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With