We help IT Professionals succeed at work.

Do I have to delete the "Default" brush for OnCtlColor "hbr"

VirtueTech
VirtueTech asked
on
Medium Priority
402 Views
Last Modified: 2009-12-16
The default brush for "OnCtlColor" is called "hbr",  but it is not a global declaration of this brush...so when I try to delete it in the "OnDestroy" function it is not usable.

Should I remove the default declaration of the brush and make it global...so I can delete it via OnDestroy? Do I have to worry about it?

Any comments are appreciated. Thanks.
Comment
Watch Question

jkr
CERTIFIED EXPERT
Top Expert 2012
Commented:
If that brush is contained in a global object, its destructor will take care about that when the program terminates. But, since your Q is quite broad, that is just an assumption that might not be too off.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Commented:
ObCtlColor usually looks like this:

HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

   // some stuff

   return hbr;
}

You don't need to release hbr. It is not created in your code, and you are not responsible for releasing it. If you don't call CDialog::OnCtlColor and return your own brush, you are responsible to release it.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.