Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing CmyprojectView from other classes 3

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
I have one other issue.

I do not know how to access CmyprojectView from other classes. In CmyfileDoc, I change some variable that is written to the screen in the OnDraw(CDC* pDC) function in CmyprojectView. I would like to call Invalidate() from CmyfileDoc so that OnDraw is called and the screen gets updated. Is there a way to do this?

I am using a SD mcf project.

Thanks
 
The doc could call UpdateAllViews and set the hint parameter to something.

The view's OnUpdate is then called and could check the hint to see what it should do, for examinple Invalidate.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
I think you can do something like this:

CmyprojectView* pView = (CmyprojectView*)GetActiveView();
pView->Invalidate();
 
From the CmyfileDoc:
Code:
CMainFrame * pMainFrame = (CMainFrame*)AfxGetMainWnd();
where CMaineFrame is the framw window class derived from the CFrameWnd 
if (pMainFrame)
{
   CmyprojectView * pView = (CmyprojectView*)pMainFrame->GetActiveView(); 
   if (pView)
      pView->Invalidate();
     // pview->InvalidateRect(NULL);
 
}

or:

CMaineFrame *pMainFrame = (CMaineFrame*)AfxGetApp()->m_pMainWnd;
if (pMainFrame)
{
   CmyprojectView * pView = (CmyprojectView*)pMainFrame->GetActiveView(); 
   if (pView)
      pView->Invalidate();
     // pview->InvalidateRect(NULL);
 
}
-obislavu-
 
Great.

I think these examples code will easily solve my problem.

Thank you all for your help.
 
Do as you wish. Personally I'd find it a bit fishy having the doc doing view-stuff (such as Invalidate).



/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
really? I have never used Visual C++ (I used to use borland builder but I can't really remember it any more).

Anyway, is this not the way things are done in visual C++?

how is it supposed to work? Data is stored in the CmyprojectDoc class, CmyprojectView handles the display...
 
Right. The idea is that the doc holds the data. It notifies the views when the data is changed, and leaves it to the views to decide what to do with it.

Its a variant of the design Observer design pattern.



/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
oh I see. so I shouldn't even have to call Invalidate if I change some data stored in the CmyprojectDoc class. It will do it automatically?
 
About CDocument::UpdateAllViews( CView* pSender, LPARAM lHint = 0L, CObject* pHint = NULL )
1.The call of this function informs each view attached to the document, except for the view specified by pSender, that the document has been modified.
2. You typically call this function from your view class after the user has changed the document through a view.
3. This function calls the CView::OnUpdate() member function for each of the document’s views except the sending view (pSender), passing pHint and lHint.
In your project , you have only one view and using UpdateAllViews() for this one the changes are not reflected in in that because it is the sender.
-obislavu-






 
>for each of the document’s views except the sending view
>using UpdateAllViews() for this one the changes are not reflected in in that because it is the sender

One can do a UpdateAllViews(NULL), to notify all views (ie sender==NULL).

The idea is that if youre already made the change to the view itself there's no need to have it being called a second time from the document. It depends in the situation of course.

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top