Completing the OnEditClearAll Function
ClassWizard adds several things to your source files when you use WizardBar to create a member function to handle a command:
A message-map entry to the class’s message map (in the .cpp file for the class).
A member function declaration to the class declaration (in the .h file for the class).
An empty member function definition to the .cpp file.
The following figure shows the starter code for OnEditClearAll
.
The OnEditClearAll Function Template
To complete the OnEditClearAll handler function
Add the following code to fill in the
OnEditClearAll
message-handler function. (Replace the highlighted //TODO comments.)DeleteContents( ); SetModifiedFlag(); UpdateAllViews( NULL );
SetModified Flag is a member function of class CDocument. It marks the document as changed so the framework will prompt the user to save the document when it closes.
The OnEditClearAll
message handler:
Calls
DeleteContents
to destroy the document’s stroke data.Scribble’s version of
DeleteContents
, from Lesson 8, Enhancing Views, overrides CDocument’s DeleteContents member function. (See To implement document cleanup.) TheDeleteContents
member function iterates through the list of strokes. For each stroke, it gets the next stroke and calls the delete operator on it.Calls the UpdateAllViews member function inherited from CDocument to cause all views of the data to be updated.
The document’s view is redrawn, this time with no data. UpdateAllViews takes a NULL argument because the document is modifying itself. The parameter is normally used to pass a pointer to the view that modified the document, but that doesn’t apply here.