Dela via


Adding an Event Handler

From the resource editor, you can add a new event handler, or edit an existing event handler, for a dialog box control using the Event Handler Wizard.

You can add an event to the class implementing the dialog box using the Properties window. If you want to add the event to a class other than the dialog box class, use the Event Handler Wizard.

To add an event handler to a dialog box control

  1. Double-click the dialog box resource in Resource View to open the dialog box resource that contains the control in the dialog editor.

  2. Right-click the control for which you want to handle the notification event.

  3. On the shortcut menu, click Add Event Handler to display the Event Handler Wizard.

  4. Select the event in the Message type box to add to the class selected in the Class list box.

  5. Accept the default name in the Function handler name box, or provide the name of your choice.

  6. Click Add and edit to add the event handler to the project and open the text editor at the new function to add the appropriate event handler code.

    If the selected message type already has an event handler for the selected class, Add and edit is unavailable, and Edit code is available. Click Edit code to open the text editor at the existing function.

Alternately, you can add event handlers from the Properties window. See Adding Event Handlers for Dialog Box Controls for more information.

See Also

Tasks

Adding a Member Variable

Adding a Member Function

Reference

Navigating the Class Structure

Concepts

Adding Functionality with Code Wizards

Adding a Class

Adding an MFC Message Handler