我要写一个网页程序,里面包含一个ATL控件,ATL控件里面有个定时器,定时触发一个事件,网页在接受到这个事件后显示当前时间,我有类是的源码,可是在ATL中我不知道如何写,就是不知道如何下手,ATL中的工具我不大会运用,那位高手能讲解一下操作步骤,最好再给我一个例子,越简单的越好,我的那个例子太大了,我都不知道从那看起,我的信箱是[email protected]
谢谢!!!!!!!!!!

解决方案 »

  1.   

    tao qian rang bie ren gei ni zuo,
    bu shi wo.
      

  2.   

    http://www.widgetware.com/ATLFAQ_ConnPoints.htm
    Active Template Library Questions
    Connection Points
    Last update on: April 01, 2002
    --------------------------------------------------------------------------------I'm having trouble with connection points, ATL, and VB5. Is there an example? (06/97) 
    How do I handle events from a ConnectPointContainer in ATL? (06/97) --------------------------------------------------------------------------------I'm having trouble with connection points, ATL, and VB5. Is there an example?Yes there is. Kevin Moule ([email protected]) has created a simple in-process ATL-based component that uses connection points to fire events to Visual Basic 5.0 (via VB5's WithEvents keyword). Here's a link to Kevin's page where you can download the source.Chapter 7 of The Active Template Library: A Developer's Guide has several connection point examples.Back to Top 
    --------------------------------------------------------------------------------How do I handle events from a ConnectPointContainer in ATL?Here's an answer provided by Dietrich Schmidt ([email protected])I coudn't find an ATL example for this. So I tried by myself and was successful. Here are the steps required: 1. create an ATL Server component which implements a connection point:1a. Define interface in IDL:interface IMyEvent : IDispatch
    {
       [id(1), helpstring("method Update")] HRESULT Update(long UpdateId);
    };
    1b. Make your main ATL class implement a connection point:public IConnectionPointImpl<CMyClass, &IID_IMyEvent, CComDynamicUnkArray>,
    public IConnectionPointContainerImpl<CMyClass>
    ...
    BEGIN_CONNECTION_POINT_MAP(CMyClass)
       CONNECTION_POINT_ENTRY(IID_IMyEvent)
    END_CONNECTION_POINT_MAP()
    1c. Send events over the connection point inside of CMyClass:   // fire event over IMyEvent
       IConnectionPointImpl<CMyClass, &IID_IMyEvent, CComDynamicUnkArray>* p = this;
       Lock();
       HRESULT hr = S_OK;
       IUnknown** pp = p->m_vec.begin();
       while (pp < p->m_vec.end() && hr == S_OK)
       {
          if (*pp != NULL)
          {
             IMyEvent* pIMyEvent = (IMyEvent*)*pp;
             hr = pIMyEvent->Update(nId);
          }
       pp++;
       }
       Unlock();
    2. Implement a client in C++, which implements IMyEvent and connects to the connection Point. First, it must retrieve an interface pointer to IMyClass, for example with CoCreateInstance. Then, you connect to the Connection Point:2a. Add the ATL headers and the global _module to you client.CComModule _Module; // ATL global Modul object
    2b. implement IMyEvent (you also need the definitions of the used IID/GUID) class CMyEvent : public IDispatchImpl<IMyEvent, &IID_IMyEvent, &LIBID_MYEXAMPLELib>, 
    public CComObjectRoot 
    {public:
       CMyEvent() {}BEGIN_COM_MAP(CMyEvent)
       COM_INTERFACE_ENTRY(IDispatch)
       COM_INTERFACE_ENTRY(IMyEvent)
    END_COM_MAP()   // IMyEvent methods
       STDMETHOD(Update)(long Id);};
    2c. connect to the connection point// connect via connection point
    CComObject<CMyEvent>::CreateInstance(&m_MyEvent);
    ASSERT(m_MyEvent);
    // give this pointer to the server
    HRESULT hr = AtlAdvise( m_pMyClass, m_MyEvent->GetUnknown(),
    IID_IMyClass, &dwAdviseHandle);
    ASSERT(SUCCEEDED(hr));
    That's it. Now you get events.Back to Top