gpt4 book ai didi

c++ - 如何在此代码上访问 webbrowser 对象? C++

转载 作者:太空宇宙 更新时间:2023-11-04 14:27:16 25 4
gpt4 key购买 nike

我找到了这个例子 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)。我怎样才能做到这一点?

最佳答案

mpWebObject 是类 webhostwnd 的成员。您可以使用代码,

IWebBrowser2* iBrowser;
mpWebObject->QueryInterface(IID_IWebBrowser2,(void**)&iBrowser);

在类中的任何位置访问浏览器界面(一旦创建了 mpWebObject)。

如果您不想使用相同的代码,here是一个更好的例子,可以满足您的目的。

关于c++ - 如何在此代码上访问 webbrowser 对象? C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2854178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com