Managing the Data

In the following procedure you’ll implement the NewStroke function that you declared earlier. NewStroke manages the stroke data in Scribble’s drawings.

To implement document members for managing Scribble’s data

Note   The new operator never returns NULL. Instead, an exception is thrown if memory could not be allocated. This would be a good place to implement an exception handler with the TRY and CATCH macros.

In the above code, NewStroke:

  1. Constructs a new CStroke object dynamically using the C++ new operator

  2. Initializes the CStroke object with the current pen width

  3. Adds the new stroke to the list using the CTypedPtrList member function AddTail

  4. Flags the document as having been modified since the last save by calling the CDocument member function SetModifiedFlag

  5. Returns a pointer to the stroke