<p>MSDN displays the following for CreatePatternBrush:</p>

<blockquote>
  <p>You can delete a pattern brush without
  affecting the associated bitmap by
  using the DeleteObject function.
  Therefore, you can then use this
  bitmap to create any number of pattern
  brushes.</p>
</blockquote>

<p>My question is the opposite. If the HBRUSH is long lived, can I delete the HBITMAP right after I create the brush? IE: does the HBRUSH store its own copy of the HBITMAP?</p>

<p>In this case, I'd like the HBRUSH to have object scope while the HBITMAP would have method scope (the method that creates the HBRUSH).</p>

[{'answer_id': 55940, 'author': 'Anthony Williams', 'author_id': 5597, 'author_profile': 'https://Stackoverflow.com/users/5597', 'pm_score': 1, 'selected': False, 'text': '<p>I think the bitmap must outlive the brush: the brush just references the existing bitmap rather than copying it.</p>\n\n<p>You could always try it and see what happened.</p>\n'}, {'answer_id': 71958, 'author': 'Matthew Xavier', 'author_id': 4841, 'author_profile': 'https://Stackoverflow.com/users/4841', 'pm_score': 1, 'selected': False, 'text': '<p>I doubt that the CreatePatternBrush() API copies the bitmap you give it, since an HBITMAP is:</p>\n\n<ol>\n<li>a GDI handle, the maximum number of which is limited, and</li>\n<li>potentially quite large.</li>\n</ol>\n\n<p>Win32 and GDI tend to be conservative about creating internal copies of your data, if only because when most of their APIs were created (CreatePatternBrush() dates to Windows 95, and many functions are older still), memory and GDI handles were in much more limited supply than they are now.  (For example, Windows 95 was required to run well on a system with only 4MB of RAM.)</p>\n'}, {'answer_id': 212372, 'author': 'Chris Becke', 'author_id': 27491, 'author_profile': 'https://Stackoverflow.com/users/27491', 'pm_score': 4, 'selected': True, 'text': '<p>The HBRUSH and HBITMAP are entirely independent. The handles can be deleted entirely independent from each other, and, once created, no changes to either object will effect the other.</p>\n'}, {'answer_id': 1006856, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>The brush does have its own copy of the bitmap. This is easily see by deleting the bitmap after creating the brush and then using the brush (works fine)</p>\n\n<p>Using GetObject to fill a LOGBRUSH structure will return the original BITMAP handle in member lbhatch, though, and not the copy's handle, unfortunately. And using GetObject on the returned bitmap handle fails if the bitmap is deleted.</p>\n\n<p>Anyone any idea how to get the original bitmap dimensions from the brush in this case? I wish to create a copy of the pattern brush even though the original bitmap is deleted. I can get a copy of the original bitmap simply by painting with the brush, but I don't know it's size. I tried using SetbrushorgEx (hdc, -1,-1), hoping the -1's would be reduced modulo its dimensions when brush selected into device context and get values when I retrieve with GetBrushOrgEx. Doesn't work.</p>\n"}]
['https://Stackoverflow.com/questions/55932', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4910/']