Search code examples
c++winapibackgrounderase

Erase window background win32API


My classmates started using Delphi with pascal but I as c++ porgrammer have to use win32 API. They were changing background color so I need to know this aswell but there are some differencies.

In delphi each form looks like it has it's own instance, and setting background color for one window is just a matter of changing one value. Not the case with win32 where when you change that value it affects every window using that class (after update ofc).

What I need to do is to clear/erase my window background. I can do that with FillRect(..) and it's working very nicely, but I've found also WM_ERASEBKGND which seems to be doing exactly what I need. They mentioned that if this message gets proccessed I should return a non-zero, but they didn't tell how to process it.

So could anything else then FillRect(and similliar) let me erase a window with a brush I defined and not with the default for class?

Thanks


Solution

  • You process WM_ERASEBKGND simply by erasing the background (using FillRect() is fine).

    By returning a non-zero value, you are simply telling Windows that this message has been taken care of and no further action is needed. There is nothing more formal than that.