The hollow brush


What is the hollow brush for?

The hollow brush is a brush that doesn't do anything. You can use it when you're forced to use a brush but you don't want to.

As one example, you can use it as your class brush. Then when your program stops responding and Windows decide to do the "white flash" (see yesterday's entry), it grabs the hollow brush and ends up not drawing anything. (At least, that's how it worked on Windows 2000. Things may be different on XP.)

Another place you can use the hollow brush is when handling the WM_CTLCOLOR* messages. Those messages require you to return a brush, which will be used to erase the background. If you don't want to erase the background, a hollow brush does the trick.

Comments (8)
  1. Mike Dimmick says:

    I think the MSDN documentation for GetStockObject needs updating:

    HOLLOW_BRUSH: Hollow brush (equivalent to NULL_BRUSH).

    NULL_BRUSH: Null brush (equivalent to HOLLOW_BRUSH).

    While on the subject of brushes, what’s the benefit (apart from not having to call SelectObject all over the place) of using the new DC brush and pen objects DC_BRUSH and DC_PEN? Is it worth rewriting existing code?

  2. Raymond Chen says:

    MSDN is fine. The "hollow brush" and the "null brush" are just two names for the same thing. Note that the null brush is not same as the NULL pointer. There is of course history behind this double-naming: It used to be called the null brush, but that proved to be easily confused with (HBRUSH)NULL, so the new name "hollow brush" was invented. The old name remains for compatibility reasons.

    The benefit of the DC pen and DC brush is that you don’t have all these brush and pen handles to worry about leaking. No reason to rewrite existing code.

  3. asdf says:

    On 2000, the null brush does nothing then after like 2 seconds it turns white. Then all redraws after that turn white immediately (while it’s still not responding).

  4. Mr. Dimmick’s point about MSDN is that MSDN gives recursive definitions but fails to give a useful definition. Mr. Chen, you gave a definition which appears far more useful than MSDN, which appears like it ought to go into MSDN in addition to the present recursion. After seeing asdf’s reply I’m not sure exactly what to suggest, but Mr. Dimmick’s point still stands.

  5. Raymond Chen says:

    Good point; I failed to notice that MSDN didn’t actually say what the hollow brush *is*. I submitted a doc change request.

  6. RichB says:

    I guess this is the NullObject pattern – in design pattern terminology.

  7. asdf says:

    Err, my comment was about when the app doesn’t respond. And it’s a tiny bit wrong too, if the app was obscured by some other window and then becomes unobscured it will blit the background of the windows that were covering it before.

  8. Pingback from  How do I get mouse messages faster than WM_MOUSEMOVE? | The Old New Thing

Comments are closed.