
The TDrawView is similar to the TMyWindow class used in previous
steps. In fact, you’ll see that a lot of the functions from TMyWindow
are brought directly to TDrawView with little or no modifications.
The TDrawView class has a number of protected data members.
TDrawView data
TDC *DragDC;
members
TPen *Pen;
TLine *Line;
TDragDocument *DrawDoc;
Three of these should look familiar to you. DragDC, P n, and Linee
perform the same function in TDrawView as they did in TMyWindow.
Although a document can exist with no associated views, the
opposite isn’t true. A view must be associated with an existing
document. TDrawView is attached to its document when it is
constructed. It keeps track of its document through a TDrawDocument
* called DrawDoc. The base class TView has a TDocument * member
called Doc that serves the same basic purpose. In fact, during base
class construction, Doc is set to point at the TDrawDocument object
passed to the TDrawView constructor DrawDoc is added to force.
proper type compliance when the document pointer is accessed.
The TDrawView constructor takes two parameters, a TDrawDocument
Creating the
& (a reference to the view’ associated document) and a TWindow * (as
TDrawView class
pointer to the parent window). The parent window defaults to 0 if no
value is supplied. The constructor passes its two parameters to the
TWindowView constructor and initializes the DrawDoc member to,
point at the document passed as the first parameter.
The constructor also sets DragDC to 0 and initializes Line with a new
TLine object.
The last thing the constructor does is set up the view’ menu. Y u cans o
use the TMenuDescr class to set up a menu descriptor from a menu
resource. Here’ the TMenuDescr constructor:s
TMenuDescr(TResId id, int fg, int eg, int cg, int og, int wg, int hg);
where:
■ id is the resource identifier of the menu resource.
■ fg is the number of menu groups in the File menu.
■ eg is the number of menu groups in the Edit menu.
■ cg is the number of menu groups in the Container menu.
84
OWL P ogrammer’ Guider s