我发现此示例http://www.mvps.org/user32/webhost.cab承载Internet Explorer WebBrowser对象,并使用此代码访问对象
void webhostwnd::CreateEmbeddedWebControl(void)
{
OleCreate(CLSID_WebBrowser,IID_IOleObject,OLERENDER_DRAW,0,&site,&storage,(void**)&mpWebObject);
mpWebObject->SetHostNames(L"Web Host",L"Web View");
// I have no idea why this is necessary. remark it out and everything works perfectly.
OleSetContainedObject(mpWebObject,TRUE);
RECT rect;
GetClientRect(hwnd,&rect);
mpWebObject->DoVerb(OLEIVERB_SHOW,NULL,&site,-1,hwnd,&rect);
IWebBrowser2* iBrowser;
mpWebObject->QueryInterface(IID_IWebBrowser2,(void**)&iBrowser);
VARIANT vURL;
vURL.vt = VT_BSTR;
vURL.bstrVal = SysAllocString(L"http://google.com");
VARIANT ve1, ve2, ve3, ve4;
ve1.vt = VT_EMPTY;
ve2.vt = VT_EMPTY;
ve3.vt = VT_EMPTY;
ve4.vt = VT_EMPTY;
iBrowser->put_Left(0);
iBrowser->put_Top(0);
iBrowser->put_Width(rect.right);
iBrowser->put_Height(rect.bottom);
iBrowser->Navigate2(&vURL, &ve1, &ve2, &ve3, &ve4);
VariantClear(&vURL);
iBrowser->Release();
}
我对cpp没有多少经验,我想知道如何从按钮或类似的东西访问同一个ie对象(例如使用Navigate2)。我怎么能做到这一点?
答案 0 :(得分:0)
mpWebObject 是 webhostwnd 类的成员。 您可以使用代码
IWebBrowser2* iBrowser;
mpWebObject->QueryInterface(IID_IWebBrowser2,(void**)&iBrowser);
在类中的任何地方访问浏览器界面(一旦创建 mpWebObject )。
如果您不想使用相同的代码,here是一个更好的例子,可以满足您的目的。