就算上面的问题不是问题,OLEFormat.GetObject的返回类型是一个LPDISPATCH,而我的控件却不是这个类型,如果我采用‘form a type library’的方式‘Add Class’,那么我的ActiveX产生的类(好象是它的接口产生的)继承于CWnd,不是COleDispatchDriver,我想不可能把LPDISPATCH赋值给它吧;如果我用#import的方式,好象继承于一个IUnKnown东西,但还没有到这步之前,我就遇到上面的问题,还没有解决呢!
//Modify the charttype of the graph.
Chart chart;
OLEFormat olefmt = shape.GetOLEFormat();
chart = olefmt.GetObject();
chart.SetChartType((long)70);
把你要持久性保存的数据声明为属性。COleControl类的持久性支持函数如下
Persistence
ExchangeExtent Serializes the control’s width and height.
ExchangeStockProps Serializes the control’s stock properties.
ExchangeVersion Serializes the control’s version number.
IsConvertingVBX Allows specialized loading of an OLE control.
SerializeExtent Serializes or initializes the display space for the control.
SerializeStockProps Serializes or initializes the COleControl stock properties.
SerializeVersion Serializes or initializes the control's version information.
SetModifiedFlag Changes the modified state of a control.
WillAmbientsBeValidDuringLoad Determines whether ambient properties will be available the next time the control is loaded.
以下例子假设一个类为MyCompany.MyActiveX的ActiveX对象在Word中被选中,DoSomething是 该对象的一个公开接口:
Dim obj as MyCompany.MyActiveX
set obj = Selection.ShapeRange(1).OLEFormat.Object
obj.DoSomething