A SERVICE OF

logo

The GetP nSize function is identical to the TMyWindow functione
GetP nSize. This function opens a TInputDialog, gets a new pen sizee
from the user and changes the pen size for the window and calls the,
SetP n function of the current line.e
The Paint function is a little different from the Paint function in the
TMyWindow class, but it does basically the same thing. Instead of
using an iterator to go through the lines in an array TDrawView::Paint,
calls the GetLine function of the view’ associated document. Thes
return from GetLine is assigned to a const TLine * called line. If line is
not 0 (that is, if GetLine returned a valid line), Paint then calls the line’s
Draw function. Remember that the TLine class is unchanged from Step
10. The line draws itself in the window.
Here’ how the code for the Paint function might look:s
void TDrawView::Paint(TDC& dc, BOOL, TRect&)
{
// Iterates through the array of line objects.
int i = 0;
const TLine* line;
while ((line = DrawDoc->GetLine(i++)) != 0)
line->Draw(dc);
}
The TDrawView class handles many of the events that were
Event handling in
previously handled by the TMyWindow class. Most of the other events
TDrawView
that TMyWindow handled that aren’t handled by TDrawView are
handled by the application object and the document manager; this is
discussed later in Step 11.
In addition, TDrawView handles two new messages: VN_COMMIT
and VN_REVERT. These view notification messages are sent by the
view’ document when the document’ Commit and Revert functionss s
are called.
Here’ the response table definition for TDrawView:s
DEFINE_RESPONSE_TABLE1(TDrawView, TWindowView)
EV_WM_LBUTTONDOWN,
EV_WM_RBUTTONDOWN,
EV_WM_MOUSEMOVE,
EV_WM_LBUTTONUP,
EV_COMMAND(CM_PENSIZE, CmPenSize),
EV_COMMAND(CM_PENCOLOR, CmPenColor),
EV_VN_COMMIT,
EV_VN_REVERT,
END_RESPONSE_TABLE;
86
OWL P ogrammer’ Guider s