Compartilhar via


Mapping Messages to Functions

The Properties window enables you to bind message handlers (member functions of MFC user-interface classes) to the messages generated by your application's resources. They use MFC message maps to create the binding.

When you use Class View to create a new class derived from one of the framework classes, it automatically places a complete and functional class in the header (.h) and implementation (.cpp) files that you specify.

Note

To add a new class that does not handle messages, create the class directly in the text editor.

To define or remove a message handler using the Properties window

  1. In Class View, click the class.

  2. In the Properties window, click the Messages button.

    Note

    The Messages button is available when you select either the class name in Class View or when you click within the source window.

    If your project has a handler for a message, then the name of the handler appears in the right column next to the message.

  3. If the message has no handler, then click the cell in the right column in the Properties window to display the suggested name of the handler as <add>HandlerName. (For example, the WM_TIMER message handler suggests <add>OnTimer).

  4. Click the suggested name to add stub code for the function.

  5. To edit a message handler, double-click the message in Class View and edit the code in the source window.

To remove a message handler, double-click the handler in the right column and select <delete>HandlerName. The function's code is commented out.

See Also

Tasks

Adding a Member Function (Visual C++)

Adding a Member Variable (Visual C++)

Overriding a Virtual Function (Visual C++)

Reference

Adding Event Handlers for Dialog Box Controls

Navigating the Class Structure (Visual C++)

Concepts

Adding an MFC Message Handler

Adding Functionality with Code Wizards

Adding a Class (Visual C++)