本文整理汇总了C++中IWebBrowser2类的典型用法代码示例。如果您正苦于以下问题:C++ IWebBrowser2类的具体用法?C++ IWebBrowser2怎么用?C++ IWebBrowser2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IWebBrowser2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpenNewWindow
// 해당 URL을 이용해 웹 브라우저를 연다.
bool CCopyProperties::OpenNewWindow(LPCTSTR pAddress)
{
IWebBrowser2 *pWebBrowser;
HRESULT hr;
// 웹브라우저 객체를 생성한다.
hr = ::CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (void**)&pWebBrowser);
if(FAILED(hr) || pWebBrowser == NULL) return FALSE;
CString strAddress = pAddress;
// Navigate()에 필요한 인자들을 초기화한다
VARIANT vtFlags, vtTarget, vtPostData, vtHeader;
::VariantInit(&vtFlags);
::VariantInit(&vtTarget);
::VariantInit(&vtPostData);
::VariantInit(&vtHeader);
// 웹브라우저를 화면에 보이게 한다
pWebBrowser->put_Visible(VARIANT_TRUE);
// 사이트를 연다
hr = pWebBrowser->Navigate(strAddress.AllocSysString(), &vtFlags, &vtTarget, &vtPostData, &vtHeader);
// 웹브라우저 인터페이스의 참조 횟수를 줄인다
pWebBrowser->Release();
return SUCCEEDED(hr);
}
示例2: LOG
IWebBrowser2* BrowserFactory::CreateBrowser() {
LOG(TRACE) << "Entering BrowserFactory::CreateBrowser";
// TODO: Error and exception handling and return value checking.
IWebBrowser2* browser;
if (this->windows_major_version_ >= 6) {
// Only Windows Vista and above have mandatory integrity levels.
this->SetThreadIntegrityLevel();
}
DWORD context = CLSCTX_LOCAL_SERVER;
if (this->ie_major_version_ == 7 && this->windows_major_version_ >= 6) {
// ONLY for IE 7 on Windows Vista. XP and below do not have Protected Mode;
// Windows 7 shipped with IE8.
context = context | CLSCTX_ENABLE_CLOAKING;
}
::CoCreateInstance(CLSID_InternetExplorer,
NULL,
context,
IID_IWebBrowser2,
reinterpret_cast<void**>(&browser));
browser->put_Visible(VARIANT_TRUE);
if (this->windows_major_version_ >= 6) {
// Only Windows Vista and above have mandatory integrity levels.
this->ResetThreadIntegrityLevel();
}
return browser;
}
示例3: CoCreateInstance
bool CMyInternetExplorer::CreateNewInstance ()
{
if (m_pWebBrowser != NULL)
{
m_pWebBrowser->Release ();
m_pWebBrowser = NULL;
}
HRESULT hr;
IWebBrowser2* pWebBrowser = NULL;
hr = CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_SERVER, IID_IWebBrowser2, (LPVOID*)&pWebBrowser);
if (SUCCEEDED (hr) && (pWebBrowser != NULL))
{
m_pWebBrowser = pWebBrowser;
m_pWebBrowser->put_Visible (VARIANT_TRUE);
return true;
}
else
{
if (pWebBrowser)
pWebBrowser->Release ();
return false;
}
return false;
}
示例4: LOG
IWebBrowser2* BrowserFactory::CreateBrowser() {
LOG(TRACE) << "Entering BrowserFactory::CreateBrowser";
IWebBrowser2* browser = NULL;
DWORD context = CLSCTX_LOCAL_SERVER;
if (this->ie_major_version_ == 7 && this->windows_major_version_ >= 6) {
// ONLY for IE 7 on Windows Vista. XP and below do not have Protected Mode;
// Windows 7 shipped with IE8.
context = context | CLSCTX_ENABLE_CLOAKING;
}
HRESULT hr = ::CoCreateInstance(CLSID_InternetExplorer,
NULL,
context,
IID_IWebBrowser2,
reinterpret_cast<void**>(&browser));
// When IWebBrowser2::Quit() is called, the wrapper process doesn't
// exit right away. When that happens, CoCreateInstance can fail while
// the abandoned iexplore.exe instance is still valid. The "right" way
// to do this would be to call ::EnumProcesses before calling
// CoCreateInstance, finding all of the iexplore.exe processes, waiting
// for one to exit, and then proceed. However, there is no way to tell
// if a process ID belongs to an Internet Explorer instance, particularly
// when a 32-bit process tries to enumerate 64-bit processes on 64-bit
// Windows. So, we'll take the brute force way out, just retrying the call
// to CoCreateInstance until it succeeds (the old iexplore.exe process has
// exited), or we get a different error code. We'll also set a 45-second
// timeout, with 45 seconds being chosen because it's below the default
// 60 second HTTP request timeout of most language bindings.
if (FAILED(hr) && HRESULT_CODE(hr) == ERROR_SHUTDOWN_IS_SCHEDULED) {
LOG(DEBUG) << "CoCreateInstance for IWebBrowser2 failed due to a "
<< "browser process that has not yet fully exited. Retrying "
<< "until the browser process exits and a new instance can "
<< "be successfully created.";
}
clock_t timeout = clock() + (45 * CLOCKS_PER_SEC);
while (FAILED(hr) &&
HRESULT_CODE(hr) == ERROR_SHUTDOWN_IS_SCHEDULED &&
clock() < timeout) {
::Sleep(500);
hr = ::CoCreateInstance(CLSID_InternetExplorer,
NULL,
context,
IID_IWebBrowser2,
reinterpret_cast<void**>(&browser));
}
if (FAILED(hr) && HRESULT_CODE(hr) != ERROR_SHUTDOWN_IS_SCHEDULED) {
// If we hit this branch, the CoCreateInstance failed due to an unexpected
// error, either before we looped, or at some point during the loop. In
// in either case, there's not much else we can do except log the failure.
LOGHR(WARN, hr) << "CoCreateInstance for IWebBrowser2 failed.";
}
if (browser != NULL) {
browser->put_Visible(VARIANT_TRUE);
}
return browser;
}
示例5:
unsigned int WINAPI Browser::GoForwardThreadProc(LPVOID param) {
HRESULT hr = ::CoInitialize(NULL);
IWebBrowser2* browser;
LPSTREAM message_payload = reinterpret_cast<LPSTREAM>(param);
hr = ::CoGetInterfaceAndReleaseStream(message_payload,
IID_IWebBrowser2,
reinterpret_cast<void**>(&browser));
hr = browser->GoForward();
return 0;
}
示例6: load_cb
static int load_cb(Ihandle* self)
{
Ihandle* txt = (Ihandle*)IupGetAttribute(self, "MY_TEXT");
IWebBrowser2 *pweb = (IWebBrowser2*)IupGetAttribute(self, "MY_WEB");
WCHAR* url = Char2Wide(IupGetAttribute(txt, "VALUE"));
// Uses the navigate method of the control
pweb->Navigate(url, NULL, NULL, NULL, NULL);
free(url);
return IUP_DEFAULT;
}
示例7: Initialize
void RedisHelpUI::Initialize()
{
CActiveXUI* pActiveXUI = static_cast<CActiveXUI*>(GetPaintMgr()->FindControl(_T("ie")));
if( pActiveXUI ) {
IWebBrowser2* pWebBrowser = NULL;
pActiveXUI->GetControl(IID_IWebBrowser2, (void**)&pWebBrowser);
// 忽略js错误
pWebBrowser->put_Silent(true);
if( pWebBrowser != NULL ) {
pWebBrowser->Navigate(L"http://redis.io/commands",NULL,NULL,NULL,NULL);
//pWebBrowser->Navigate(L"about:blank",NULL,NULL,NULL,NULL);
pWebBrowser->Release();
}
}
}
示例8: CenterWindow
void CFrameWnd::InitWindow()
{
// SetIcon(IDR_MAINFRAME); // 设置任务栏图标
CenterWindow();
// 初始化CActiveXUI控件
CActiveXUI* pActiveXUI = static_cast<CActiveXUI*>(m_PaintManager.FindControl(_T("ActiveXDemo1")));
if( pActiveXUI )
{
IWebBrowser2* pWebBrowser = NULL;
pActiveXUI->SetDelayCreate(false); // 相当于界面设计器里的DelayCreate属性改为FALSE,在duilib自带的FlashDemo里可以看到此属性为TRUE
pActiveXUI->CreateControl(CLSID_WebBrowser); // 相当于界面设计器里的Clsid属性里填入{8856F961-340A-11D0-A96B-00C04FD705A2},建议用CLSID_WebBrowser,如果想看相应的值,请见<ExDisp.h>
pActiveXUI->GetControl(IID_IWebBrowser2, (void**)&pWebBrowser);
if( pWebBrowser != NULL )
{
//pWebBrowser->Navigate(L"https://code.google.com/p/duilib/",NULL,NULL,NULL,NULL);
pWebBrowser->Navigate(L"about:blank", NULL, NULL, NULL, NULL);
pWebBrowser->Navigate(L"http://www.baidu.com/", NULL, NULL, NULL, NULL); // 由于谷歌时不时被墙,所以换成反应快的网站
pWebBrowser->Release();
}
}
// 初始化CProgressUI控件
CProgressUI* pProgress = static_cast<CProgressUI*>(m_PaintManager.FindControl(_T("ProgressDemo1")));
pProgress->SetValue(50);
// 初始化CListUI控件
CDuiString str;
CListUI* pList = static_cast<CListUI*>(m_PaintManager.FindControl(_T("ListDemo1")));
for (int i = 0; i < 100; i++)
{
CListTextElementUI* pListElement = new CListTextElementUI;
pListElement->SetTag(i);
pList->Add(pListElement);
str.Format(_T("%d"), i);
pListElement->SetText(0, str);
pListElement->SetText(1, _T("haha"));
}
}
示例9: GetLocationUrl
std::wstring GetLocationUrl(IWebBrowser2& browser)
{
ATL::CComBSTR locationUrl;
if (FAILED(browser.get_LocationURL(&locationUrl)) || !locationUrl)
{
return std::wstring();
}
return std::wstring(locationUrl, locationUrl.Length());
}
示例10: main
int main(int argc, char **argv)
{
Ihandle* txt, *bt;
IupOpen(&argc, &argv);
IupOleControlOpen();
// Creates an instance of the WebBrowser control
Ihandle* control = IupOleControl("Shell.Explorer.2");
// Sets production mode
IupSetAttribute(control, "DESIGNMODE", "NO");
// Creates a dialog containing the OLE control
Ihandle* dlg = IupDialog(IupVbox(IupHbox(txt = IupText(""), bt = IupButton("Load", NULL), NULL), control, NULL));
IupSetAttribute(dlg, "TITLE", "IupOle");
IupSetAttribute(dlg, "MY_TEXT", (char*)txt);
IupSetAttribute(txt, "EXPAND", "HORIZONTAL");
IupSetCallback(bt, "ACTION", (Icallback)load_cb);
// Maps the dialog to force the creation of the control
IupMap(dlg);
// Gathers the IUnknown pointer to access the control's interface
IUnknown* punk = (IUnknown*) IupGetAttribute(control, "IUNKNOWN");
IWebBrowser2 *pweb = NULL;
punk->QueryInterface(IID_IWebBrowser2, (void **)&pweb);
punk->Release();
IupSetAttribute(dlg, "MY_WEB", (char*)pweb);
// Shows dialog
IupShow(dlg);
IupMainLoop();
// Releases the control interface
pweb->Release();
IupClose();
return EXIT_SUCCESS;
}
示例11: CRect
void CBetaPatchClientDlg::CreateWebControl( LPCTSTR szURL )
{
// AFX_IDW_PANE_FIRST is a safe but arbitrary ID
#ifdef __LANG_JAP
//JAPAN 패치 클라이언트 이미지 변경관련 웹 크기 조절.
if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, "", WS_VISIBLE | WS_CHILD, CRect(14, 14, 466, 447),
this, AFX_IDW_PANE_FIRST))
#else //__LANG_JAP
#if __CURRENT_LANG == LANG_KOR //공지사항 크기 확장 관련 조정.
if (!m_wndBrowser.CreateControl(CLSID_WebBrowser,
"", WS_VISIBLE | WS_CHILD, CRect(26, 190, 452, 447), this, AFX_IDW_PANE_FIRST))
#else //LANG_KOR
if (!m_wndBrowser.CreateControl(CLSID_WebBrowser,
"",
WS_VISIBLE | WS_CHILD,
CRect(26, 263, 452, 447),
this,
AFX_IDW_PANE_FIRST))
#endif //LANG_KOR
#endif //__LANG_JAP
{
return;
}
IWebBrowser2* pBrowser;
LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &pBrowser);
if (SUCCEEDED(hr))
{
CString strURL( szURL );
BSTR bstrURL = strURL.AllocSysString();
COleSafeArray vPostData;
LPCTSTR lpszTargetFrameName = NULL;
LPCTSTR lpszHeaders = NULL;
pBrowser->Navigate(bstrURL,
COleVariant((long) 0, VT_I4),
COleVariant(lpszTargetFrameName, VT_BSTR),
vPostData,
COleVariant(lpszHeaders, VT_BSTR));
}
}
示例12: GetClientRect
void CWebDlg::OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)
{
/* CRect r;
GetClientRect(&r);
ClientToScreen(&r);
m_dlgLoading.MoveWindow(r.left+BROWSER_X, r.top+BROWSER_Y, BROWSER_W, BROWSER_H);
m_dlgLoading.ShowWindow(SW_SHOW);*/
// set the user agent to nel_launcher changing the header
CString csHeader(Headers->bstrVal);
if(csHeader.IsEmpty())
{
IWebBrowser2 *pBrowser;
LPDISPATCH pWebDisp;
pDisp->QueryInterface(IID_IWebBrowser2, (void**) &pBrowser);
pBrowser->get_Container(&pWebDisp);
BSTR bstr = SysAllocString(L"User-Agent: nel_launcher\r\n");
Headers->bstrVal = bstr;
pBrowser->Navigate2(URL, Flags, TargetFrameName, PostData, Headers);
if (!pWebDisp)
(*Cancel) = true;
if (pWebDisp)
pWebDisp->Release();
if (pBrowser)
pBrowser->Release();
SysFreeString(bstr);
return;
}
}
示例13: closeAllInternetExplorers
DWORD Application_InternetExplorer::closeAllInternetExplorers(IClassFactory* internet_explorer_factory) {
DWORD iReturnVal;
iReturnVal = 0;
// Create another fake IE instance so that we can close the process
IWebBrowser2* pInternetExplorer;
HRESULT hr = internet_explorer_factory->CreateInstance(NULL, IID_IWebBrowser2,
(void**)&pInternetExplorer);
if( hr == S_OK )
{
OutputDebugStringA("IE CloseAll created fake IE instance.\n");
HWND hwndIE;
DWORD dProcessId;
pInternetExplorer->get_HWND((SHANDLE_PTR*)&hwndIE);
GetWindowThreadProcessId(hwndIE, &dProcessId);
// Close the IE process - try 1
EnumWindows(Application_InternetExplorer::EnumWindowsProc, (LPARAM)dProcessId);
// Close the IE process - try 2
HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, dProcessId);
DWORD tempProcessId = GetProcessId(hProc);
if(tempProcessId == dProcessId)
{
if(!TerminateProcess(hProc, 0))
{
iReturnVal = GetLastError();
OutputDebugStringA("IE CloseAll unable to terminate 1.\n");
}
}
if( hProc != NULL) {
CloseHandle( hProc );
}
}
if(pInternetExplorer!=NULL) {
pInternetExplorer->Release();
}
//then all processes that match the exe
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) {
OutputDebugStringA("IE CloseAll couldn't enum processes.\n");
iReturnVal = -1;
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
for ( i = 0; i < cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
std::wstring processName = L"c:\\Program Files\\Internet Explorer\\iexplore.exe";
size_t iPos = processName.find_last_of(L"\\");
processName.erase(0, iPos +1);
if(compareName(aProcesses[i], processName)==0)
{
OutputDebugStringA("IE CloseAll IE process left over. Closing....\n");
EnumWindows(Application_InternetExplorer::EnumWindowsCloseAppProc, (LPARAM) aProcesses[i]);
HANDLE hPro = OpenProcess(PROCESS_TERMINATE,TRUE, aProcesses[i]);
if(!TerminateProcess(hPro, 0))
{
iReturnVal = GetLastError();
OutputDebugStringA("IE CloseAll unable to terminate 2.\n");
}
if( hPro != NULL ) {
CloseHandle (hPro);
}
}
}
}
return iReturnVal;
}
示例14: CC_BREAK_IF
bool Win32WebControl::createWebView(
const std::function<bool (const std::string &)> &shouldStartLoading,
const std::function<void (const std::string &)> &didFinishLoading,
const std::function<void (const std::string &)> &didFailLoading,
const std::function<void (const std::string &)> &onJsCallback)
{
bool ret = false;
IConnectionPointContainer *container = NULL;
do
{
HWND hwnd = cocos2d::Director::getInstance()->getOpenGLView()->getWin32Window();
_winContainer.Create(hwnd, NULL, NULL, WS_CHILD | WS_VISIBLE);
HRESULT hr;
hr = _winContainer.CreateControl(L"shell.Explorer.2");
CC_BREAK_IF(FAILED(hr));
hr = _winContainer.QueryControl(__uuidof(IWebBrowser2), (void **)&_webBrowser2);
CC_BREAK_IF(FAILED(hr) || _webBrowser2 == NULL);
_webBrowser2->put_Silent(VARIANT_TRUE);
VARIANT var;
VariantInit(&var);
var.vt = VT_BSTR;
var.bstrVal = SysAllocString(L"about:blank");
hr = _webBrowser2->Navigate2(&var, NULL, NULL, NULL, NULL);
SysFreeString(var.bstrVal);
VariantClear(&var);
CC_BREAK_IF(FAILED(hr));
hr = _webBrowser2->QueryInterface(IID_IConnectionPointContainer, (void **)&container);
CC_BREAK_IF(FAILED(hr));
hr = container->FindConnectionPoint(DIID_DWebBrowserEvents2, &_connectionPoint);
CC_BREAK_IF(FAILED(hr));
hr = _connectionPoint->Advise(this, &_cookie);
CC_BREAK_IF(FAILED(hr));
hr = _webBrowser2->get_Document(&_htmlDoc);
CC_BREAK_IF(FAILED(hr));
ret = true;
} while (0);
if (!ret)
{
removeWebView();
}
if (container != NULL)
{
container->Release();
container = NULL;
}
_shouldStartLoading = shouldStartLoading;
_didFinishLoading = didFinishLoading;
_didFailLoading = didFailLoading;
_onJsCallback = onJsCallback;
return ret;
}
示例15: VariantInit
void Win32WebControl::loadURL(BSTR url) const
{
VARIANT var;
VariantInit(&var);
var.vt = VT_BSTR;
var.bstrVal = url;
_webBrowser2->Navigate2(&var, NULL, NULL, NULL, NULL);
VariantClear(&var);
}