Getting a Pointer to DC from Document
-
Dear All, how can I get a pointer to DC (that is associated with the View):-> from the document class? I need a pointer to DC to do some manipulation... I am using:
CDC *pDC = AfxGetMainWnd()->GetDC(); .... .... AfxGetMainWnd()->ReleaseDC();
but it's not working as expected... - A programmer's national anthem; "AAAAAHHHHH!!!!" -
Dear All, how can I get a pointer to DC (that is associated with the View):-> from the document class? I need a pointer to DC to do some manipulation... I am using:
CDC *pDC = AfxGetMainWnd()->GetDC(); .... .... AfxGetMainWnd()->ReleaseDC();
but it's not working as expected... - A programmer's national anthem; "AAAAAHHHHH!!!!"You can use CDocument::GetFirstViewPosition / GetNextView to get the view windows. Then, as CView inherits from CWnd, you can use CWnd::GetDC to get the view's DC. If you are in a SDI app, you can get the view straight away. In am MDI view, you potentially need to iterate ythrough them. Another alternative, is to us CDocument::UpdateAllView (...) with a custom lParam, and let the views draw on themselves. A CDocument is supposed to have no idea about how its data is displayed - thats the point of separating them! Iain.
-
You can use CDocument::GetFirstViewPosition / GetNextView to get the view windows. Then, as CView inherits from CWnd, you can use CWnd::GetDC to get the view's DC. If you are in a SDI app, you can get the view straight away. In am MDI view, you potentially need to iterate ythrough them. Another alternative, is to us CDocument::UpdateAllView (...) with a custom lParam, and let the views draw on themselves. A CDocument is supposed to have no idea about how its data is displayed - thats the point of separating them! Iain.
Iain Clarke wrote:
A CDocument is supposed to have no idea about how its data is displayed
Yup! but we break the rules sometimes! ;) Actually, I just need a refrence to a DC (the View's DC) to set some parameters, I am not doing any drawing... - A programmer's national anthem; "AAAAAHHHHH!!!!"