Udostępnij za pośrednictwem


Adding Event Handlers for Dialog Box Controls

For project dialog boxes that are already associated with a class, you can take advantage of some shortcuts when you create event handlers. You can quickly create a handler either for the default control notification event or for any applicable Windows message.

To create a handler for the default control notification event

  1. Double-click the control. The Text editor opens.

  2. Add control notification handler code in the Text editor.

To create a handler for any applicable Windows message

  1. Click the control for which you want to handle the notification event.

  2. In the Properties window, click the ControlEvents button to display the list of common Windows events associated with the control. For example, the standard OK button on the About dialog box lists the following notification events:

    BN_CLICKED

    BN_DOUBLECLICKED

    BN_KILLFOCUS

    BN_SETFOCUS

    Note

    Alternately, select the dialog box and click the ControlEvents button to display the list of common Windows events for all controls in the dialog box.

  3. In the Properties window, click the right column next to the event to handle, and then select the suggested notification event name (for example, OnBnClickedOK handles BN_CLICKED).

    Note

    Alternately, you can provide an event handler name of your choice, rather than selecting the default event handler name.

    Once you have selected the event, Visual Studio opens the Text Editor and displays the event handler's code. For example, the following code is added for the default OnBnClickedOK:

    void CAboutDlg::OnBnClickedOk(void)
    {
       // TODO: Add your control notification handler code here
    }
    

If you want to add the event handler to a class other than the one implementing the dialog box, use the Event Handler wizard. For more information, see Adding an Event Handler.

For information on adding resources to managed projects, please see Resources in Applications in the .NET Framework Developer's Guide. For information on manually adding resource files to managed projects, accessing resources, displaying static resources, and assigning resources strings to properties, see Walkthrough: Localizing Windows Forms and Walkthrough: Using Resources for Localization with ASP.NET.

Requirements

Win32

See Also

Tasks

Defining Member Variables for Dialog Controls

Adding a Member Function

Adding a Member Variable

Overriding a Virtual Function

Reference

Default Control Events

Dialog Box Controls and Variable Types

Concepts

Adding a Class

Adding an MFC Message Handler