我想写一个activex控件,一接受某个消息,就触发一个事件.然后在引用这个控件的程序里,写代码来实现这个事件.就象 mscomm 那样,会提供一个 on_comm 事件给别的程序用.怎么做?哪位好心人有例子给我看一看吧?

解决方案 »

  1.   

    see vs.net 2003 sample -- polygon
      

  2.   

    1. 控件中实现连接点
    BEGIN_CONNECTION_POINT_MAP(CFireTabCtrl)
    CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
    CONNECTION_POINT_ENTRY(__uuidof(_IFireTabCtrlEvents))
    END_CONNECTION_POINT_MAP()
       When your container query for connection point, this will tell the container which connection point it supports and wait to sink.
    2。_IFireTabCtrlEvents是控件中的idl定义的,你可以往这里加入event.
    3。container implement _IFireTabCtrlEvents interface
    4. 在控件的BEGIN_MSG_MAP和END_MSG_MAP中加入 MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
    5. 在OnRButtonDown中调用container的_IFireTabCtrlEvents->SomeEventYouDefined();
      

  3.   

    接收方
    BEGIN_SINK_MAP()
       SINK_ENTRY_EX
    END_SINK_MAP()