OLE 控件怎么插入到richEdit中

                                               OLE 控件怎么插入到richEdit

STDMETHODIMP CMyGifCtrl::InsertGifIntoRichEditCtrl(BSTR sGifPath, HWND hwndRichEditCtrl, DWORD dwUserData) { //保存 RichEdit 容器 句柄 m_hwndRichEditParent=hwndRichEditCtrl; //保存传入的gif的路径 m_strGifPath=(LPOLESTR)sGifPath; //保存dwUser m_dwUser=dwUserData; IStorage* lpStorage = NULL; //存储接口 LPLOCKBYTES lpLockBytes = NULL; HRESULT hr = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);//创建LOCKBYTE对象 if( FAILED(hr) ) _com_issue_error(hr); hr = ::StgCreateDocfileOnILockBytes(lpLockBytes,//创建复合文档 STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage); if (hr != S_OK) { lpLockBytes = NULL; //AfxThrowOleException(hr); return S_FALSE; } //通过发送EM_GETOLEINTERFACE消息来获取 RichEdit控件的 IRichEditOle接口指针。 IRichEditOle* pRichEditOle = NULL; ::SendMessage(hwndRichEditCtrl, EM_GETOLEINTERFACE, (WPARAM) 0, (LPARAM)&pRichEditOle); if(!pRichEditOle) { return E_NOINTERFACE; } //获得 IOleClientSite接口指针,每个嵌入到RichEdit控件的对象都必须使用由GetClientSite返回的这个接口。 IOleClientSite* pOleClientSite = NULL; pRichEditOle->GetClientSite(&pOleClientSite); if (!pOleClientSite) { pRichEditOle->Release(); return E_NOINTERFACE; } //通知CGifOleCtrl对象在它的容器里面(RichEdit)的显示的位置。 HRESULT hSetClientSite= SetClientSite(pOleClientSite); if (hSetClientSite==S_OK) { OutputDebugString(_T("SetClientSite S_OK /r/n")); } else { OutputDebugString(_T("SetClientSite Fail /r/n")); } if (FAILED(LoadGifPath(sGifPath))) { pOleClientSite->Release(); pRichEditOle->Release(); return E_FAIL; } OleSetContainedObject((LPOLEOBJECT)this, TRUE); REOBJECT reo = { sizeof REOBJECT}; reo.cp = REO_CP_SELECTION; reo.clsid = __uuidof(IGGGifCtrl) ; reo.poleobj = (IOleObject*)this; reo.polesite = pOleClientSite; reo.dvaspect = DVASPECT_CONTENT; reo.dwFlags = /*REO_DYNAMICSIZE*/REO_BELOWBASELINE; reo.pstg = lpStorage; reo.dwUser = dwUserData; SIZEL sizel; sizel.cx = sizel.cy = 0; reo.sizel = sizel; //插入一个对象到 RichEdit控件中 HRESULT hRet=pRichEditOle->InsertObject(&reo); if (hRet==S_OK) { OutputDebugString(_T("InsertObject S_OK /r/n")); } else { hRet=GetScode(hRet); OutputDebugString(_T("InsertObject Fail /r/n")); } //通知容器,嵌入的OLE对象将要显示或者隐藏。 pOleClientSite->OnShowWindow(true); pOleClientSite->OnShowWindow(false); pOleClientSite->Release(); pRichEditOle->Release(); return S_OK; }

 

你可能感兴趣的:(null,存储,文档)