description | title | ms.date | helpviewer_keywords | ms.assetid | |||
---|---|---|---|---|---|---|---|
Learn more about: Delegate and interface map macros |
Delegate and Interface Map Macros (MFC) |
03/30/2017 |
|
3840e642-ff7d-4bdc-998b-c7d8fc50890e |
MFC supports these macros for delegate and interface maps:
Name | Description |
---|---|
BEGIN_DELEGATE_MAP | Begins a delegate map. |
BEGIN_INTERFACE_MAP | Begins the definition of the interfaced map. |
CommandHandler Delegate | Registers callback methods with a command source. |
END_DELEGATE_MAP | Ends a delegate map. |
END_INTERFACE_MAP | Ends the interface map in the implementation file. |
EVENT_DELEGATE_ENTRY | Creates an entry in the delegate map. |
INTERFACE_PART | Used between the BEGIN_INTERFACE_MAP macro and the END_INTERFACE_MAP macro for each interface your object will support. |
MAKE_DELEGATE | Attaches an event handler to a managed control. |
Begins a delegate map.
BEGIN_DELEGATE_MAP( CLASS );
CLASS
The class in which the managed control is hosted.
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 EVENT_DELEGATE_ENTRY.
Header: msclr\event.h
Begins the definition of the interfaced map when used in the implementation file.
BEGIN_INTERFACE_MAP( theClass, baseClass )
theClass
The class in which the interface map is to be defined
baseClass
The class from which theClass derives from.
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.
Header: afxwin.h
Registers callback methods with a command source.
delegate void CommandHandler( UINT^ cmdID );
cmdID
The command ID.
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.
Header: afxwinforms.h (defined in assembly atlmfc\lib\mfcmifc80.dll)
Registers callback methods with a user interface update command message.
delegate void CommandUIHandler( unsigned int cmdID, ICommandUI^ cmdUI);
cmdID
The command ID.
cmdUI
The command message ID.
This delegate registers callback methods with a user interface update command message. CommandUIHandler
is similar to CommandHandler 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.
Header: afxwinforms.h (defined in assembly atlmfc\lib\mfcmifc80.dll)
Ends a delegate map.
END_DELEGATE_MAP();
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 EVENT_DELEGATE_ENTRY.
Header: msclr\event.h
Ends the interface map in the implementation file.
END_INTERFACE_MAP( )
For more information about interface maps, see Technical Note 38.
Header: afxwin.h
Creates an entry in the delegate map.
EVENT_DELEGATE_ENTRY(MEMBER, ARG0, ARG1);
MEMBER
The event handler method to be attached to the control.
ARG0
The first argument of the managed event handler method, such as Object^
.
ARG1
The second argument of the managed event handler method, such as EventArgs^
.
Each entry in the delegate map corresponds to a managed event handler delegate created by MAKE_DELEGATE.
The following code example shows how to use EVENT_DELEGATE_ENTRY to create an entry in the delegate map for the OnClick
event handler; also see the code example in MAKE_DELEGATE. For more information, see How to: Sink Windows Forms Events from Native C++ Classes.
BEGIN_DELEGATE_MAP(CMyView)
EVENT_DELEGATE_ENTRY(OnClick, System::Object^, System::EventArgs^)
END_DELEGATE_MAP()
Header: msclr\event.h
Used between the BEGIN_INTERFACE_MAP macro and the END_INTERFACE_MAP macro for each interface your object will support.
INTERFACE_PART( theClass, iid, localClass)
theClass
The name of the class that contains the interface map.
iid
The IID that is to be mapped to the embedded class.
localClass
The name of the local class.
It allows you to map an IID to a member of the class indicated by theClass and localClass.
For more information on interface maps, see Technical Note 38.
Header: afxwin.h
Attaches an event handler to a managed control.
MAKE_DELEGATE( DELEGATE, MEMBER) ;
DELEGATE
The type of the managed event handler delegate, such as EventHandler.
MEMBER
The name of the event handler method to be attached to the control.
This macro creates a managed event handler delegate of type DELEGATE and of the name MEMBER. The managed event handler delegate allows a native class to handle managed events.
The following code example shows how to call MAKE_DELEGATE
to attach an OnClick
event handler to an MFC control MyControl
. For a broader explanation of how this macro works in an MFC application, see How to: Sink Windows Forms Events from Native C++ Classes.
// CMyView derives from CWinFormsView.
void CMyView::OnInitialUpdate()
{
CWinFormsView::OnInitialUpdate();
GetControl()->Click += MAKE_DELEGATE(System::EventHandler, OnClick);
}
Header: msclr\event.h
How to: Sink Windows Forms Events from Native C++ Classes
How to: Add Command Routing to the Windows Forms Control
Macros and Globals