So sánh macro và class trong c

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Delegate and interface map macros

  • Bài viết
  • 08/03/2021

Trong bài viết này

MFC supports these macros for delegate and interface maps:

Name Description Begins a delegate map. Begins the definition of the interfaced map. Registers callback methods with a command source. Ends a delegate map. Ends the interface map in the implementation file. Creates an entry in the delegate map. Used between the BEGIN_INTERFACE_MAP macro and the END_INTERFACE_MAP macro for each interface your object will support. Attaches an event handler to a managed control.

BEGIN_DELEGATE_MAP

Begins a delegate map.

Syntax

BEGIN_DELEGATE_MAP(  CLASS );

Parameters

CLASS The class in which the managed control is hosted.

Remarks

This macro marks the beginning of a list of delegate entries, which compose a delegate map. For an example of how this macro is used, see .

Requirements

Header: msclr\event.h

BEGIN_INTERFACE_MAP

Begins the definition of the interfaced map when used in the implementation file.

Syntax

BEGIN_INTERFACE_MAP( theClass, baseClass )

Parameters

theClass The class in which the interface map is to be defined

baseClass The class from which theClass derives from.

Remarks

For each interface that is implemented, there is one or more INTERFACE_PART macro invocations. For each aggregate that the class uses, there is one INTERFACE_AGGREGATE macro invocation.

For more information on interface maps, see Technical Note 38.

Requirements

Header: afxwin.h

CommandHandler Delegate

Registers callback methods with a command source.

Syntax

delegate void CommandHandler(  UINT^ cmdID  );

Parameters

cmdID The command ID.

Remarks

This delegate registers callback methods with a command source. When you add a delegate to the command source object, the callback method becomes a handler for commands coming from the specified source.

For more information, see How to: Add Command Routing to the Windows Forms Control.

For more information on using Windows Forms, see Using a Windows Form User Control in MFC.

Requirements

Header: afxwinforms.h (defined in assembly atlmfc\lib\mfcmifc80.dll)

CommandUIHandler

Registers callback methods with a user interface update command message.

Syntax

delegate void CommandUIHandler(  unsigned int cmdID, ICommandUI^ cmdUI);

Parameters

cmdID The command ID.

cmdUI The command message ID.

Remarks

This delegate registers callback methods with a user interface update command message.

BEGIN_INTERFACE_MAP( theClass, baseClass )

1 is similar to except that this delegate is used with user interface object update commands. User interface update commands should be mapped one-to-one with message handler methods.

For more information on using Windows Forms, see Using a Windows Form User Control in MFC.

Requirements

Header: afxwinforms.h (defined in assembly atlmfc\lib\mfcmifc80.dll)

END_DELEGATE_MAP

Ends a delegate map.

Syntax

END_DELEGATE_MAP();

Remarks

This macro marks the end of a list of delegate entries, which compose a delegate map. For an example of how this macro is used, see .

Requirements

Header: msclr\event.h

END_INTERFACE_MAP

Ends the interface map in the implementation file.

Syntax

END_INTERFACE_MAP( )

Remarks

For more information about interface maps, see Technical Note 38.

Requirements

Header: afxwin.h

EVENT_DELEGATE_ENTRY

Creates an entry in the delegate map.

Syntax

EVENT_DELEGATE_ENTRY(MEMBER, ARG0, ARG1);

Parameters

MEMBER The event handler method to be attached to the control.

ARG0 The first argument of the managed event handler method, such as

BEGIN_INTERFACE_MAP( theClass, baseClass )

2.

ARG1 The second argument of the managed event handler method, such as

BEGIN_INTERFACE_MAP( theClass, baseClass )

3.

Remarks

Each entry in the delegate map corresponds to a managed event handler delegate created by .

Example

The following code example shows how to call

BEGIN_INTERFACE_MAP( theClass, baseClass )

5 to attach an

BEGIN_INTERFACE_MAP( theClass, baseClass )

4 event handler to an MFC control

BEGIN_INTERFACE_MAP( theClass, baseClass )

7. For a broader explanation of how this macro works in an MFC application, see How to: Sink Windows Forms Events from Native C++ Classes.