1
votes

I have an MFC SDI application and I want to access the Document area from a separate Dialog so I can draw something on it. Here's what I want to access:

void CProjView::OnDraw(CDC* pDC)

or better yet, I would like to draw on the document view directly from the dialog. How can I do that ?

1

1 Answers

3
votes

If you want to draw something in the document than it should probably be in your document. Get a pointer to your CDocument class and call CDocument::UpdateAllViews. It in turn will call CView::OnUpdate. You will set a flag there and call Invalidate(). The OnDraw() will now redraw the screen with the new object since you set the flag telling it to do so.

There are other ways where you can just grab the device context of the client area and start drawing but the problem there is that if you minimize the window and restore it back, the new painting will be lost. In fact anything that you do outside of OnDraw() function will be lost. Therefore you must do all your drawing in OnDraw() function and the above is how to do it systematically using doc/view architecture.