The next task is to pass the hint to the document’s UpdateAllViews member function. You must pass a hint each time a stroke is completed.
To pass the hint after modifying the document
OnLButtonUp
member function of class CScribbleView
and add the following code, just before the ReleaseCapture
function call:// Tell the stroke item that we're done adding points to it.
// This is so it can finish computing its bounding rectangle.
m_pStrokeCur->FinishStroke();
// Tell the other views that this stroke has been added
// so that they can invalidate this stroke's area in their
// client area.
pDoc->UpdateAllViews(this, 0L, m_pStrokeCur);
The OnLButtonUp
member function is called when a stroke is finished, so you call UpdateAllViews from there. In this function, the view gets the hint information that it will send to the document. It does this by calling the FinishStroke
member function for m_pStrokeCur
; FinishStroke
computes the bounding rectangle for the current stroke. Then the view calls UpdateAllViews, passing two arguments: the this pointer, which identifies this view as the one that performed the modification to the document, and m_pStrokeCur
, whose bounding rectangle is the hint. (The function sends a pointer to the entire CStroke
object rather than just the bounding rectangle because the hint must be a CObject pointer, and CRect isn’t derived from CObject.) The view doesn’t need to send any more hint information, so it passes nothing (0) in the LPARAM parameter.
The UpdateAllViews function iterates through the list of views attached to the document; for each view (except the one that performed the modification), the function calls its OnUpdate function and passes the hint as a parameter.