client ocx
ocx function subject (provide service)
ocx event (for callback) subject
1) event in CSharp/Delphi is only a funcion pointer, no concreate body,
but ocx event has a body, it used FireEvent to invoke the client application's event handler
//in ocx
void CMyOcxCtrl1Ctrl::OnMyEvent1(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
//client call back
//Call CWinClientDlg::OnMyEvent1Myocxctrl1ctrl1()
FireEvent(dispidOnMyEvent1, EVENT_PARAM(VTS_NONE));
}
// in client application
BEGIN_EVENTSINK_MAP(CWinClientDlg, CDialog)
ON_EVENT(CWinClientDlg, IDC_MYOCXCTRL1CTRL1, 1, OnMyEvent1Myocxctrl1ctrl1, VTS_NONE)
END_EVENTSINK_MAP()
void CWinClientDlg::OnMyEvent1Myocxctrl1ctrl1()
{
AfxMessageBox("CWinClientDlg::OnMyEvent1Myocxctrl1ctrl1()");
}
2) if you set some output parameter in event, you can query client application's data
(event is not only for client to define self-call back)
ocx function subject (provide service)
ocx event (for callback) subject
1) event in CSharp/Delphi is only a funcion pointer, no concreate body,
but ocx event has a body, it used FireEvent to invoke the client application's event handler
//in ocx
void CMyOcxCtrl1Ctrl::OnMyEvent1(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
//client call back
//Call CWinClientDlg::OnMyEvent1Myocxctrl1ctrl1()
FireEvent(dispidOnMyEvent1, EVENT_PARAM(VTS_NONE));
}
// in client application
BEGIN_EVENTSINK_MAP(CWinClientDlg, CDialog)
ON_EVENT(CWinClientDlg, IDC_MYOCXCTRL1CTRL1, 1, OnMyEvent1Myocxctrl1ctrl1, VTS_NONE)
END_EVENTSINK_MAP()
void CWinClientDlg::OnMyEvent1Myocxctrl1ctrl1()
{
AfxMessageBox("CWinClientDlg::OnMyEvent1Myocxctrl1ctrl1()");
}
2) if you set some output parameter in event, you can query client application's data
(event is not only for client to define self-call back)