ActiveX Control Fundamentals

来源:互联网 发布:matlab 数组 差分 编辑:程序博客网 时间:2024/05/16 17:12

From http://www.pluralsight.com/articlecontent/cpprep0199.htm:

Here we are, eight functions later, and we have an ActiveX control which can be embedded in any control container. This doesn't mean that you shouldn't reach for your nearest C++ library the next time you need to implement a control, but hopefully you have a better perspective on what that library is doing for you, and where to look when things don't behave as you expect.

It should be noted that the ActiveX support in Visual C++ (ATL and MFC) is much more than this simple implementation

From http://community.csdn.net/expert/Topicview2.asp?id=4868028

我一直搞不清楚,到底我创建的控件窗口在IE窗口中的位置是由我来管理还是由IE来管理,其实这根本不用我来操心。
  我一直以为是我只负责现实接口,容器主动来找接口,所以我一直觉得很奇怪,为什么IE没来找IOleInPlaceObject接口。现在发现其实不然,有的时候是要我来通知容器来拿接口的,IOleInPlaceObject就是这种情况。
  我在DoVerb收到OLEIVERB_INPLACEACTIVATE时,首先当然是创建我的控件窗口。然后,是关键一步,通过容器的IOleClientSite接口找到IOleInPlaceSite接口,然后调用IOleInPlaceSite->OnInPlaceActivate();这样IE就会来找IOleInPlaceObject接口了。在IOleInPlaceObject的GetWindow中我把我创建的控件窗口返回给容器,就这样,我的控件窗口就会归容器管辖,拖动滚动条时容器会根据情况移动我的控件窗口,根本不用我操心了。