In addition to storing the current pen width in m_nPenWidth
, class CScribbleDoc
needs to keep track of whether the pen is currently thick or thin and how “thick” and “thin” are defined (in pixels). You do this by adding new data members for the thick and thin pen values. In Connecting a Class to a Dialog Box, in Scribble’s next lesson, you will add code to allow the user to define these values with a dialog box. For now, the default values will be hard coded.
To add the new data members
CScribbleDoc
.
Locate the section labeled “// Attributes:
”.
m_nPenWidth
declaration, add the following code:BOOL m_bThickPen; // Thick currently selected or not
UINT m_nThinWidth; // Current definition of thin
UINT m_nThickWidth; // Current definition of thick
Tip You could also right-click CScribbleDoc in ClassView and click Add Member Variable to add these three variables.
To hard code the values
InitDocument
(in ScribbleDoc.cpp), and add the following code just before the call to ReplacePen:
m_bThickPen = FALSE;
m_nThinWidth = 2; // Default thin pen is 2 pixels wide
m_nThickWidth = 5; // Default thick pen is 5 pixels wide
The added code specifies that the pen is initially thin and defines the meanings of “thin” and “thick.”
ClassView displays icons for the new member variables in class CScribbleDoc
.