在word中添加并显示一个ActiveX控件,vc代码,一直不成功,请教

1 篇文章 0 订阅
1 篇文章 0 订阅
方法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);


请不吝赐教,万分感谢。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值