Редагувати

Поділитися через


Defining a Message Handler for a Reflected Message

Once you have created a new MFC control class, you can define message handlers for it. Reflected message handlers allow your control class to handle its own messages before the message is received by the parent. You can use the MFC CWnd::SendMessage function to send messages from your control to a parent window.

With this functionality you could, for example, create a list box that will redraw itself rather than relying on the parent window to do so (owner drawn). For more information on reflected messages, see Handling Reflected Messages.

To create an ActiveX control with the same functionality, you must create a project for the ActiveX control.

Note

You cannot add a reflected message (OCM_Message) for an ActiveX control using the Class Wizard, as described below. You must add these messages manually.

To define a message handler for a reflected message from the Class Wizard

  1. Add a control, such as a list, a rebar control, a toolbar, or a tree control, to your MFC project.

  2. In Class View, click the name of your control class.

  3. In the Class Wizard, the control class name appears in the Class Name list.

  4. Click the Messages tab to display the Windows messages available to add to the control.

  5. Select the reflected message for which you want to define a handler. Reflected messages are marked with an equal sign (=).

  6. Click the cell in the right column in the Class Wizard to display the suggested name of the handler as <add>HandlerName. (For example, the =WM_CTLCOLOR message handler suggests <add>CtlColor).

  7. Click the suggested name to accept. The handler is added to your project.

  8. To edit or delete a message handler, repeat steps 4 through 7. Click the cell containing the handler name to edit or delete and click the appropriate task.

See also

Mapping Messages to Functions
Adding Functionality with Code Wizards
Adding a Class
Adding a Member Function
Adding a Member Variable
Overriding a Virtual Function
MFC Message Handler
Navigating the Class Structure