C++/Destruction of CDC class
Expert: Zlatko - 4/23/2010
QuestionHi again, Zlatko.
I am working on a VC++6 Graph program that analyses the contents of a file.
When the user clicks anywhere on the graph, text comes up with identifying information regarding that location within the file.
I'm using: CDC* pDC = this->GetDC(); as a constructor since OnLMouseDown won't accept another argument(I think it's called 'overloading') CDC* pDC within its parentheses. Then of course, I add the code to make the text visible on the graph.
My problem is that I don't know what to use as a destructor for the CDC class. I'm currently using 'this->ReleaseDC(pDC)', but is this sufficient?
Thank you for taking your time to read, analyze and answer my note,
-Neil
AnswerHello Neil. I'm not really experienced in this part of MFC, but according to the msdn documentation, a release is all that is necessary. The GetDC is not really a constructor, it just gets the window's device context, so it would be incorrect to delete the DC. Have a look at
http://msdn.microsoft.com/en-us/library/71eseab0%28VS.80%29.aspx
There is some information about when a DC should not be released. I would test the program with releasing, and if there are no problems, keep it in.
Sorry that I could not give you a more definite answer. Try posting your question to an MFC forum.
Best regards
Zlatko