方法1:
//通过Word接ISl得到当前活动文档pDoc
CComQIPtr<MSWORD::_Document> pDoc;
m_spApp->get_ActiveDocument(&pDoc);
//调用文档保护类型属性接口得到文档保护类型,并以此来判断在文档中
//是否添加新的签章。 CComQIPtr<MSWORD::Shapes> pShapes;
pDoc->get_Shapes(&pShapes);
CComQIPtr<MSWORD::Shape> pShape;
VARIANT type,anchor;
VARIANT m_left,m_top,m_width,m_hight;
VariantInit(&type);
VariantInit(&m_left);
VariantInit(&m_top);
VariantInit(&m_width);
VariantInit(&m_hight);
VariantInit(&anchor); type.vt=VT_BSTR;
type.bstrVal =::SysAllocString(L"DEMOPIC.DemoPicCtrl.1");
m_left.vt=VT_I4; m_left.lVal = 30;
m_top.vt=VT_I4; m_top.lVal = 30;
m_width.vt=VT_I4; m_width.lVal = 50;
m_hight.vt=VT_I4; m_hight.lVal = 50; anchor.vt=VT_I4; anchor.lVal = 30; pShapes->AddOLEControl(&type,&m_left,&m_top,&m_width,&m_hight,&anchor,&pShape);
VariantClear(&type);
VariantClear(&m_left);
VariantClear(&m_top);
VariantClear(&m_width);
VariantClear(&m_hight);
VariantClear(&anchor);方法2: //通过Word接ISl得到当前活动文档pDoc
CComQIPtr<MSWORD::_Document> pDoc;
m_spApp->get_ActiveDocument(&pDoc);
//调用文档保护类型属性接口得到文档保护类型,并以此来判断在文档中
//是否添加新的签章。 CComQIPtr<MSWORD::InlieShapes> pShapes;
pDoc->get_InlineShapes(&pShapes);
CComQIPtr<MSWORD::InlineShape> pShape;
VARIANT type,rg;
VariantInit(&type);
VariantInit(&rg); type.vt=VT_BSTR;
type.bstrVal =::SysAllocString(L"DEMOPIC.DemoPicCtrl.1");
rg.vt=VT_I4; rg.lVal = 30; pShapes->AddOLEControl(&type,&rg,&pShape);
VariantClear(&type);
VariantClear(&rg);
请不吝赐教,万分感谢。
//通过Word接ISl得到当前活动文档pDoc
CComQIPtr<MSWORD::_Document> pDoc;
m_spApp->get_ActiveDocument(&pDoc);
//调用文档保护类型属性接口得到文档保护类型,并以此来判断在文档中
//是否添加新的签章。 CComQIPtr<MSWORD::Shapes> pShapes;
pDoc->get_Shapes(&pShapes);
CComQIPtr<MSWORD::Shape> pShape;
VARIANT type,anchor;
VARIANT m_left,m_top,m_width,m_hight;
VariantInit(&type);
VariantInit(&m_left);
VariantInit(&m_top);
VariantInit(&m_width);
VariantInit(&m_hight);
VariantInit(&anchor); type.vt=VT_BSTR;
type.bstrVal =::SysAllocString(L"DEMOPIC.DemoPicCtrl.1");
m_left.vt=VT_I4; m_left.lVal = 30;
m_top.vt=VT_I4; m_top.lVal = 30;
m_width.vt=VT_I4; m_width.lVal = 50;
m_hight.vt=VT_I4; m_hight.lVal = 50; anchor.vt=VT_I4; anchor.lVal = 30; pShapes->AddOLEControl(&type,&m_left,&m_top,&m_width,&m_hight,&anchor,&pShape);
VariantClear(&type);
VariantClear(&m_left);
VariantClear(&m_top);
VariantClear(&m_width);
VariantClear(&m_hight);
VariantClear(&anchor);方法2: //通过Word接ISl得到当前活动文档pDoc
CComQIPtr<MSWORD::_Document> pDoc;
m_spApp->get_ActiveDocument(&pDoc);
//调用文档保护类型属性接口得到文档保护类型,并以此来判断在文档中
//是否添加新的签章。 CComQIPtr<MSWORD::InlieShapes> pShapes;
pDoc->get_InlineShapes(&pShapes);
CComQIPtr<MSWORD::InlineShape> pShape;
VARIANT type,rg;
VariantInit(&type);
VariantInit(&rg); type.vt=VT_BSTR;
type.bstrVal =::SysAllocString(L"DEMOPIC.DemoPicCtrl.1");
rg.vt=VT_I4; rg.lVal = 30; pShapes->AddOLEControl(&type,&rg,&pShape);
VariantClear(&type);
VariantClear(&rg);
请不吝赐教,万分感谢。
CComQIPtr <Office::_CommandBarButton> spBtn1(Ctrl);
CComQIPtr <Word::_Application> spApp;
CComQIPtr <Word::_Document> spDoc;
CComQIPtr<Word::InlineShapes> pShapes;
spApp=spBtn1->GetApplication();
spDoc = spApp->GetActiveDocument(); pShapes = spDoc->GetInlineShapes();
CComQIPtr<Word::InlineShape> pShape;
VARIANT type,rg;
VariantInit(&type);
VariantInit(&rg); type.vt=VT_BSTR;
type.bstrVal =::SysAllocString(L"TESTACTIVEX.TestActiveXCtrl.1");
rg.vt=VT_I4; rg.lVal = 30; pShape = pShapes->AddOLEControl(&type);
VariantClear(&type);
VariantClear(&rg);用上面代码,word加载控件后,事件可以触发。
但是文档保存,再打开后,控件就变成了图片,不在触发事件。请大家继续讨论。感谢