如何从一个 OCX 获取 IDispatch Excel 或 Word 文档的

发布网友 发布时间:2022-03-17 04:25

我来回答

2个回答

懂视网 时间:2022-03-17 08:46

uptodate临床助手有很多资料能学习,可以很大的帮助医学院学生,那么应该如何进行注册呢,接下来就给朋友们分享一下具体的操作方法。

第一步:打开uptodate软件。

第二步:点击注册。

第三步:根据提示完成注册,注意只有一个月试用期,以后需要购买。

以上便是针对该问题所整理出来的具体操作步骤,希望可以帮助到需要的朋友。

热心网友 时间:2022-03-17 05:54

  执行步骤的示例

  创建名为 OffCntrDisp 的新 MFC ActiveX 控件向导应用程序。
  COleControl 派生类中添加下面的成员变量:
  char m_szDocName[512];
  IDispatch *m_pDocDisp;

  注: m_szDocName 保存包含我们的控制的文档的名称并且 m_pDocDisp 是该文档的 IDispatch 接口。

  COleControl 派生类定义中的末尾添加以下项:
  // Interface Maps.
  protected:
  // IoleObject.
  BEGIN_INTERFACE_PART(MyOleObject, IOleObject)
  INIT_INTERFACE_PART(COffCtlDispCtrl, MyOleObject)
  STDMETHOD(SetClientSite)(LPOLECLIENTSITE);
  STDMETHOD(GetClientSite)(LPOLECLIENTSITE*);
  STDMETHOD(SetHostNames)(LPCOLESTR, LPCOLESTR);
  STDMETHOD(Close)(DWORD);
  STDMETHOD(SetMoniker)(DWORD, LPMONIKER);
  STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER*);
  STDMETHOD(InitFromData)(LPDATAOBJECT, BOOL, DWORD);
  STDMETHOD(GetClipboardData)(DWORD, LPDATAOBJECT*);
  STDMETHOD(DoVerb)(LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND,
  LPCRECT);
  STDMETHOD(EnumVerbs)(IEnumOLEVERB**);
  STDMETHOD(Update)();
  STDMETHOD(IsUpToDate)();
  STDMETHOD(GetUserClassID)(CLSID*);
  STDMETHOD(GetUserType)(DWORD, LPOLESTR*);
  STDMETHOD(SetExtent)(DWORD, LPSIZEL);
  STDMETHOD(GetExtent)(DWORD, LPSIZEL);
  STDMETHOD(Advise)(LPADVISESINK, LPDWORD);
  STDMETHOD(Unadvise)(DWORD);
  STDMETHOD(EnumAdvise)(LPENUMSTATDATA*);
  STDMETHOD(GetMiscStatus)(DWORD, LPDWORD);
  STDMETHOD(SetColorScheme)(LPLOGPALETTE);
  END_INTERFACE_PART(MyOleObject)

  DECLARE_INTERFACE_MAP();

  这将重写您的自定义 MyOleObject 与 IOleObject COleControl 的默认实现。

  COleControl 派生类的构造函数中添加以下代码:
  m_pDocDisp = NULL;
  紧随其后 OffCntrDispCtl.cpp 中的以下行:
  IMPLEMENT_OLECTLTYPE(COffCntrDispCtrl, IDS_OFFCNTRDISP,

  _dwOffCntrDispOleMisc)

  添加以下代码:
  BEGIN_INTERFACE_MAP(COffCntrDispCtrl, COleControl)
  INTERFACE_PART(COffCntrDispCtrl, IID_IOleObject, MyOleObject)
  END_INTERFACE_MAP()

  此操作,请在步骤 3 中所做的修改以及覆盖 COleControl 的 IOleObject。

  第 5 步中添加的代码,下面添加以下代码:
  static char buf[8192];
  static void DoMsg(char *msg) {
  ::MessageBox(NULL, msg, "Message", MB_SETFOREGROUND);
  }

  static void DoErr(char *msg, long err) {
  static char errBuf[8192];
  sprintf(errBuf, "%s, Error: %ld (%08lx)", msg, err,err);
  ::MessageBox(NULL, errBuf, "Error", MB_SETFOREGROUND);
  }

  这些都是以后用于显示邮件的有用例程。

  将粘贴的所有以下代码在您的 OffCntrDispCtl.cpp 文件的末尾:
  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::SetHostNames(LPCOLESTR
  pwApp, LPCOLESTR pwObj)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);

  // Convert OLESTR into ASCII string.

  WideCharToMultiByte(CP_ACP, 0, pwObj, -1, pThis->m_szDocName,
  512, NULL, NULL);

  // Get IDispatch.
  pThis->GetDocDispatch();

  // Test it out by getting the document name.
  pThis->TestDispatch();

  return S_OK;
  }

  STDMETHODIMP
  COffCntrDispCtrl::XMyOleObject::SetClientSite(LPOLECLIENTSITE
  pClientSite)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.SetClientSite(pClientSite);
  }

  STDMETHODIMP
  COffCntrDispCtrl::XMyOleObject::SetColorScheme(LPLOGPALETTE plp)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.SetColorScheme(plp);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::GetMiscStatus(DWORD
  dwAspect, DWORD* pdwStatus)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.GetMiscStatus(dwAspect, pdwStatus);
  }

  STDMETHODIMP
  COffCntrDispCtrl::XMyOleObject::EnumAdvise(LPENUMSTATDATA*
  ppenumAdvise)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.EnumAdvise(ppenumAdvise);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::Unadvise(DWORD
  dwConnection)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.Unadvise(dwConnection);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::Advise(LPADVISESINK
  pAdvSink, DWORD* pdwConnection)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.Advise(pAdvSink, pdwConnection);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::GetExtent(DWORD
  dwDrawAspect, LPSIZEL lpsizel)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.GetExtent(dwDrawAspect, lpsizel);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::SetExtent(DWORD
  dwDrawAspect, LPSIZEL lpsizel)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.SetExtent(dwDrawAspect, lpsizel);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::GetUserType(DWORD
  dwFormOfType, LPOLESTR* ppszUserType)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);

  return pThis->m_xOleObject.GetUserType(dwFormOfType,
  ppszUserType);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::GetUserClassID(CLSID*
  pClsid)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.GetUserClassID(pClsid);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::IsUpToDate()
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);

  return pThis->m_xOleObject.IsUpToDate();
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::Update()
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.Update();
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::EnumVerbs(LPENUMOLEVERB*
  ppenumOleVerb)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);

  return pThis->m_xOleObject.EnumVerbs(ppenumOleVerb);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::DoVerb(LONG iVerb, LPMSG
  lpmsg, LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent,
  LPCRECT lprcPosRect)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.DoVerb(iVerb, lpmsg, pActiveSite,
  lindex, hwndParent, lprcPosRect);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::GetClipboardData(DWORD
  dwReserved, LPDATAOBJECT *ppDataObject)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.GetClipboardData(dwReserved,
  ppDataObject);
  }

  STDMETHODIMP
  COffCntrDispCtrl::XMyOleObject::InitFromData(LPDATAOBJECT
  pDataObject, BOOL fCreation, DWORD dwReserved)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.InitFromData(pDataObject, fCreation,
  dwReserved);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::GetMoniker(DWORD
  dwAssign, DWORD dwWhichMoniker, LPMONIKER *ppmk)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.GetMoniker(dwAssign, dwWhichMoniker,
  ppmk);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::SetMoniker(DWORD
  dwWhichMoniker, LPMONIKER pmk)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.SetMoniker(dwWhichMoniker, pmk);
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::Close(DWORD
  dwSaveOption)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.Close(dwSaveOption);
  }

  STDMETHODIMP
  COffCntrDispCtrl::XMyOleObject::GetClientSite(LPOLECLIENTSITE*
  ppClientSite)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.GetClientSite(ppClientSite);

  }

  STDMETHODIMP_(ULONG) COffCntrDispCtrl::XMyOleObject::Release()
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.Release();
  }

  STDMETHODIMP_(ULONG) COffCntrDispCtrl::XMyOleObject::AddRef()
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.AddRef();
  }

  STDMETHODIMP COffCntrDispCtrl::XMyOleObject::QueryInterface(REFIID
  iid, LPVOID* ppvObj)
  {
  METHOD_MANAGE_STATE(COffCntrDispCtrl, MyOleObject)
  ASSERT_VALID(pThis);
  return pThis->m_xOleObject.QueryInterface(iid, ppvObj);
  }

  这是您的 IOleObject,通常将委托其调用默认 COleControl 的 IOleObject 实现,除 SetHostNames() 之外的所有实现。补漏白,SetHostNames(),并存储该文档的名称插入控件的位置。

  遗憾的是,Microsoft PowerPoint 不能调用此方法,因此,此示例将不会使用该产品。但是,Microsoft Powerpoint 是单个服务器,因此您可以使用 GetActiveObject() 来唯一获得 IDispatch 指针。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com