In procedures that follow, you’ll add new member variables (m_nPenWidth
and m_penCur
) and functions (InitDocument
and NewStroke
) to CScribbleDoc
.
Note The source files for tutorials such as Scribble contain comments that clarify the purpose of the code. Including such comments is not always mentioned as part of a tutorial step, both for brevity’s sake, and because the purpose of code you add is explained in the procedures you’ll follow. You can modify or add to comments in your own files.
To add member variables to Scribble’s document class
CScribbleDoc
. In the menu, click Add Member Variable.The Add Member Variable dialog box appears.
UINT
.m_nPenWidth
.ClassWizard adds the variable declaration to file ScribbleDoc.h.
m_penCur
variable of type CPen.ClassView displays the new member declarations and variables you’ve added with your code.
CScribbleDoc
.
Note that m_nPenWidth
and m_penCur
are now displayed as variables belonging to the class. Once member functions and variables are declared, ClassView displays them, even if their definition isn’t written yet.
m_nPenWidth
.
ScribbleDoc.h places the cursor at the definition for m_nPenWidth
.
CTypedPtrList<CObList, CStroke*> m_strokeList;
CPen* GetCurrentPen( ) { return &m_penCur; }
The first line is an instance of a template. The second is the definition of an inline function, so its definition appears here instead of in ScribbleDoc.cpp.
To add member functions to Scribble’s document class
CScribbleDoc
.CStroke*
.NewStroke()
.A declaration is added to ScribbleDoc.h, while a starter definition is added to ScribbleDoc.cpp. You’ll fill in the definition later in this lesson.
InitDocument
. In the Function Type box, type void
, and in the Access area, click Protected.Note The development environment saves all your work for you automatically when you build your project, close the workspace, or exit the program. Any prompts within these procedures to save your files are provided only as extra safeguards of your work.
You can view the new functions using ClassView.