我写了一个测试网页
<BODY>
<OBJECT ID="test2" CLASSID="CLSID:D1413D1E-0868-4158-A556-9463E13F4B13"></OBJECT>
<OBJECT ID="test" CLASSID="CLSID:723531DF-C92C-44CB-BC14-49B9C917A594"></OBJECT>
<script>
test2.attachEvent("OnTest", Ontest2);
test.attachEvent("OnTest", Ontest);
test.test();
test2.test();
function Ontest2()
{
alert("test2");
}
function Ontest()
{
alert("test");
}
</script>
</BODY>
其中test2是用ATL建立的一个full control,Apartment模型,dual接口,支持连接点.
test是用ATL建立的一个simple object,Apartment模型,dual接口,支持连接点.
这两个对象都增加了事件OnTest,并且都在test方法中调用了Fire_OnTest();
但是网页运行的结果是只弹出对话框"test2".请问要怎样才能在用simple object的情况下使用事件

解决方案 »

  1.   

    http://groups.google.com/group/microsoft.public.vc.atl/browse_thread/thread/746df98b5c75f906/65cf79a77ad62795?lnk=st&q=%22simple+object%22+event+atl+internet+explorer&rnum=1&hl=en#65cf79a77ad62795When using theATL, the following 'lite control' ATL objects do not implement the IProvideClassInfo2 interface by default: You can easily add support for event handling by implementing the 
    IProvideClassInfo interfaces. This is done by deriving your control from the 
    default ATL implementation, IProvideClassInfo2Impl. 
    1. Add the following line to your class derivation list: 
          public IProvideClassInfo2Impl<&CLSID_<object_name>, NULL, 
                                      &LIBID_<project_name>Lib> 
    2. Add the following lines to your COM_MAP: 
          COM_INTERFACE_ENTRY(IProvideClassInfo) 
          COM_INTERFACE_ENTRY(IProvideClassInfo2) 
    Hope that helps. For additional information you can take a look at KB Q200839