请问这样插入网页为什么不行
IStorage* lpStorage = NULL;//存储接口
IOleObject* lpOleObject = NULL;//OLE对象
LPLOCKBYTES lpLockBytes = NULL;//LOCKBYTE
IOleClientSite* lpOleClientSite = NULL;
CComPtr<IWebBrowser2> lpPolyCtl = NULL; //控件
CLSID clsid;
REOBJECT reobject;
HRESULT hr;
IRichEditOle *lpRichEditOle =m_RichEdit.GetIRichEditOle();
if(lpRichEditOle == NULL)
return ;
//创建PolyCtl对象并获取接口
hr = ::CoCreateInstance(CLSID_WebBrowser,NULL,CLSCTX_INPROC,IID_IWebBrowser2,(LPVOID*)&lpPolyCtl);
//hr = ::CoCreateInstance(CLSID_InternetExplorer,NULL,CLSCTX_LOCAL_SERVER,IID_IWebBrowser2,(LPVOID*)&lpPolyCtl);
if( lpPolyCtl == NULL )
{
return ;
}
// USES_CONVERSION;
BOOL bRet = TRUE;
try{
hr = lpPolyCtl->QueryInterface(IID_IOleObject,(void **)&lpOleObject);//获得数据对象接口
if( hr != S_OK )
AfxThrowOleException(hr);
hr = lpOleObject->GetUserClassID(&clsid);
if ( hr != S_OK)
AfxThrowOleException(hr);
hr = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);//创建LOCKBYTE对象
if (hr != S_OK)
AfxThrowOleException(hr);
ASSERT(lpLockBytes != NULL);
hr = ::StgCreateDocfileOnILockBytes(lpLockBytes,//创建复合文档
STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage);
if (hr != S_OK)
{
VERIFY(lpLockBytes->Release() == 0);
lpLockBytes = NULL;
AfxThrowOleException(hr);
}
lpRichEditOle->GetClientSite(&lpOleClientSite);
ZeroMemory(&reobject, sizeof(REOBJECT));//初始化一个对象
reobject.cbStruct = sizeof(REOBJECT);
reobject.clsid = clsid;
reobject.cp = REO_CP_SELECTION;
reobject.dvaspect = DVASPECT_CONTENT;
reobject.dwFlags = REO_BELOWBASELINE;
reobject.poleobj = lpOleObject;
reobject.polesite = lpOleClientSite;
reobject.pstg = lpStorage;
lpOleObject->SetClientSite(lpOleClientSite);//
hr = lpRichEditOle->InsertObject( &reobject );
if (hr != S_OK)
AfxThrowOleException(hr);
OleSetContainedObject(lpOleObject,TRUE);
hr = lpPolyCtl->Navigate(L"www.baidu.com",NULL,NULL,NULL,NULL);
if (hr != S_OK)
AfxThrowOleException(hr);
::SendMessage(m_RichEdit.GetSafeHwnd(), EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
lpOleObject->DoVerb(OLEIVERB_UIACTIVATE, NULL, lpOleClientSite, 0,
m_RichEdit.m_hWnd, NULL);
lpOleObject->DoVerb(OLEIVERB_SHOW, NULL, lpOleClientSite, 0, m_RichEdit.m_hWnd,
NULL);
m_RichEdit.RedrawWindow();
}
catch( COleException* e )
{
TRACE(_T("OleException code:%d"),e->m_sc);
e->Delete();
bRet = FALSE;
}
// release the interface
//if( lpPolyCtl != NULL ) lpPolyCtl->Release();
if( lpOleObject != NULL ) lpOleObject->Release();
if( lpOleClientSite != NULL ) lpOleClientSite->Release();
if( lpStorage != NULL ) lpStorage->Release();
return ;
回复 更多评论