The hollow brush

Date:January 26, 2004 / year-entry #34
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20040126-00/?p=40903
Comments:    8
Summary: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...

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.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index