Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 3.7 KB

adding-event-handlers-for-dialog-box-controls.md

File metadata and controls

65 lines (43 loc) · 3.7 KB
title Adding Event Handlers for Dialog Box Controls (C++)
ms.date 06/28/2018
helpviewer_keywords
Dialog Editor [C++], adding event handlers to controls
controls [C++], event handlers
dialog box controls [C++], events
event handlers, for dialog box controls
ms.assetid f9c70f24-ea6f-44df-82eb-78a2deaee769

Adding Event Handlers for Dialog Box Controls (C++)

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 Desktop Apps in the .NET Framework Developer's Guide. For information on manually adding resource files to managed projects, accessing resources, displaying static resources, and assigning resource strings to properties, see Creating Resource Files for Desktop Apps. For information on globalization and localization of resources in managed apps, see Globalizing and Localizing .NET Framework Applications.

Requirements

Win32

See Also

Default Control Events
Defining Member Variables for Dialog Controls
Dialog Box Controls and Variable Types
Adding a Class
Adding a Member Function
Adding a Member Variable
Overriding a Virtual Function
MFC Message Handler