?
Solved

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

Posted on 2006-04-03
2
Medium Priority
?
307 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.
0
Comment
Question by:VirtueTech
2 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 400 total points
ID: 16367275
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 1600 total points
ID: 16367837
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question