How to: Sink Windows Forms Events from Native C++ Classes

JavaScript EditorDhtml editor     Free javascript download 



Main Page

You can enable native C++ classes to receive callbacks from managed events raised from Windows Forms controls or other forms with the MFC macro map format. Sinking events in views and dialogs is similar to doing the same task for controls.

To do this, you need to:

Example

This sample continues the work you did in How to: Do DDX/DDV Data Binding with Windows Forms.

Now, you will associate your MFC control (m_MyControl) with a managed event handler delegate called OnClick for the managed Click event.

Add the first line of code to implementation of BOOL CMFC01Dlg::OnInitDialog.

Add the delegate map and OnClick definition to the public section in the declaration of class CMFC01Dlg : public CDialog.

В CopyCode imageCopy Code
m_MyControl.GetControl()->button1->Click += MAKE_DELEGATE( System::EventHandler, OnClick );

// delegate map
BEGIN_DELEGATE_MAP( CMFC01Dlg )
EVENT_DELEGATE_ENTRY( OnClick, System::Object^, System::EventArgs^ )
END_DELEGATE_MAP()

   void OnClick( System::Object^ sender, System::EventArgs^ e ) {}

See Also

Reference

MAKE_DELEGATE
BEGIN_DELEGATE_MAP
END_DELEGATE_MAP
EVENT_DELEGATE_ENTRY



JavaScript EditorDhtml editor     Free javascript download