This topic has not yet been rated - Rate this topic

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

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:

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.

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 ) {}
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.