Bind Scribble’s Clear All Command to Its Handler Code
As discussed in the previous topic, Which Command-Target Class Gets the Handler?, Scribble’s Clear All command is bound to the document class.
To create the starter handler for Scribble’s Clear All command
In FileView, expand the Source Files folder, if necessary, and double-click the icon for ScribbleDoc.cpp to open the file.
Recall the decision to handle the command from the document rather than the view. That’s why the handler for Clear All will be placed in
CScribbleDoc
.Click the action button arrow located on the right end of WizardBar.
Click Add Windows Message Handler.
The New Windows Message Handler dialog box appears.
In the Class or object to handle box, select ID_EDIT_CLEAR_ALL.
In the New Windows messages to handle list box, select COMMAND.
You can see both COMMAND and UPDATE_COMMAND_UI in the New Windows messages to handle list box. These are the two events for which the framework provides ClassWizard support in creating your command handler code. That’s why, for commands, these are always the choices you see in this list box. In other cases, you might see other things listed — a list of Windows messages, for example, when the selected item is the name of a window or view class.
Later in the lesson, in Update Scribble’s Clear All Menu Item, you’ll see how UPDATE_COMMAND_UI is used for this menu command.
Click Add and Edit.
In the Add Member Function dialog box, click OK to accept the name
OnEditClearAll
.The following figure shows the selections from steps 3 through 7.
Clear All in WizardBar
ClassWizard creates the starter handler function at the end of ScribbleDoc.cpp and highlights the //TODO comments where you will add the code, which is described in the next procedure, To complete the OnEditClearAll handler function.