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

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.
VirtueTechAsked:
Who is Participating?
 
AlexFMCommented:
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.
0
 
jkrCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.