// 해당 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); }
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; }
HWND MkWebBrowser::Open(const MkStr& pageUrl, int posX, int posY, int width, int height) { if (pageUrl.Empty()) return NULL; HRESULT hr; IWebBrowser2* pWebBrowser = NULL; VARIANT vtHeader2 = {0}; VARIANT vtTarget2 = {0}; VARIANT vtEmpty2 = {0}; vtHeader2.vt = VT_BSTR; vtHeader2.bstrVal = SysAllocString(L"Content-Type: application/x-www-form-urlencoded\r\n"); vtTarget2.vt = VT_BSTR; vtTarget2.bstrVal = SysAllocString(L"_top"); VariantInit(&vtEmpty2); CoInitialize(NULL); CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (void**)&pWebBrowser); pWebBrowser->put_Width((long)width); pWebBrowser->put_Height((long)height); pWebBrowser->put_Left((long)posX); pWebBrowser->put_Top((long)posY); pWebBrowser->put_MenuBar(VARIANT_FALSE); pWebBrowser->put_ToolBar(VARIANT_FALSE); pWebBrowser->put_AddressBar(VARIANT_FALSE); pWebBrowser->put_StatusBar(VARIANT_FALSE); BSTR cBuf = SysAllocString(pageUrl.GetPtr()); hr = pWebBrowser->Navigate(cBuf, &vtEmpty2, &vtTarget2, &vtEmpty2, &vtHeader2); SysFreeString(cBuf); SysFreeString(vtHeader2.bstrVal); SysFreeString(vtTarget2.bstrVal); HWND exh = NULL; if (SUCCEEDED(hr)) { pWebBrowser->put_Visible(VARIANT_TRUE); pWebBrowser->get_HWND((long*)&exh); } else { pWebBrowser->Quit(); } pWebBrowser->Release(); CoUninitialize(); return exh; }
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(); } } }
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")); } }
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; }
void Win32WebControl::removeWebView() { if (_connectionPoint != NULL) { _connectionPoint->Unadvise(_cookie); _connectionPoint->Release(); _connectionPoint = NULL; } if (_htmlDoc != NULL) { _htmlDoc->Release(); _htmlDoc = NULL; } if (_webBrowser2 != NULL) { _webBrowser2->Release(); _webBrowser2 = NULL; } _winContainer.DestroyWindow(); }
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; } }
~Win32HtmlViewRep(){ inPlaceObject->Release(); iBrowser->Release(); oleObject->Close(OLECLOSE_NOSAVE); oleObject->Release(); }
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; }
void CMainDialog::OnClick( CControlUI* pSender) { if (pSender->GetName() == TEXT ("btnExit")) { PostQuitMessage(0); return; } else if (pSender->GetName() == _T ("btnTip")) { CControlUI* pbtnTip = static_cast <CControlUI*> (m_pm.FindControl(_T ("btnTip"))); if (pbtnTip) { pbtnTip->SetVisible(false); } CEditUI* peditSearch = static_cast <CEditUI*> (m_pm.FindControl(_T ("editSearch"))); if (peditSearch != NULL) { peditSearch->SetFocus(); } } else if (pSender->GetName() == _T ("lstDelButton")) { int iIndex = 0; CMyList* pParent = static_cast <CMyList*> (pSender->GetParent()->GetParent()); if (pParent) { iIndex = pParent->GetItemIndex(pSender->GetParent()); } CDuiString str; str.Format(_T ("您要删除 %d 项"), iIndex); if (IDNO == MessageBox (GetHWND (), str, NULL, MB_OK | MB_YESNO)) return; CMyList* pList = static_cast <CMyList*> (m_pm.FindControl(_T ("lstControl"))); ASSERT(pList); if (pList) { pList->RemoveAt(iIndex); CControlUI* pItem = pList->GetItemAt(iIndex+5); if (pItem) { const RECT& rc = pItem->GetPos(); SIZE sz = {0, rc.top}; pList->SetScrollPos(sz); } } } else if (pSender->GetName() == _T ("btnAddComboItem")) { CComboUI* pcbx = static_cast <CComboUI*> (m_pm.FindControl(_T ("combo1"))); assert (pcbx); if (pcbx) { CListLabelElementUI* pItem = new CListLabelElementUI (); pItem->SetText(_T ("{b}{i}新加项{/i}{/b}")); pcbx->Add(pItem); } AddComboboxItem(); CComboUI* pcbx2 = static_cast <CComboUI*> (m_pm.FindControl(_T ("combo2"))); } else if (pSender->GetName() == _T ("btnGoIe")) { CActiveXUI* pActiveXUI = static_cast<CActiveXUI*>(m_pm.FindControl(_T("ie"))); if( pActiveXUI ) { IWebBrowser2* pWebBrowser = NULL; pActiveXUI->GetControl(IID_IWebBrowser2, (void**)&pWebBrowser); if( pWebBrowser != NULL ) { CEditUI* pEdit = static_cast <CEditUI*> (m_pm.FindControl(_T ("editIePath"))); ASSERT (pEdit); CDuiString strIePath = _T ("www.baidu.com"); if (pEdit) { strIePath = pEdit->GetText(); } WCHAR szPath [1024] = {0}; #if defined(_UNICODE) || defined(UNICODE) lstrcpyW (szPath, strIePath); #else ::MultiByteToWideChar(CP_ACP, 0, strIePath, -1, szPath, 1023); #endif pWebBrowser->Navigate(szPath,NULL,NULL,NULL,NULL); pWebBrowser->Release(); } } } }
void CQuizWnd::ShowQuiz(int ndx) { assert(m_songInfo); assert(m_question); auto& quizInfo = m_songInfo->GetQuizInfo(); auto quiz = quizInfo.get_quiz(ndx - 1); if (!quiz) return; // show question std::wstring html_path = m_songInfo->get_tmp_path() + L"\\" + m_songInfo->get_id() + L"\\question.html"; std::wofstream out(html_path); if (!out.is_open())return; std::wstringstream ss; ss << L"<HTML>" L"<head>" L"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" L"<title>lyric</title>" L"</head>" L"<BODY SCROLL=NO bgcolor='#FFFFBF' topmargin='2' leftmargin='2'>" L"<h3 align='LEFT'>" L"<font size='5' color=#000000>" << quiz->get_question() << L"</font>" L"</h3>" L"</BODY>" L"</HTML>"; std::wstring w = ss.str(); std::string u; utf8::utf16to8(w.begin(), w.end(), std::back_inserter(u)); out << u.c_str(); out.close(); m_question->Navigate(const_cast<wchar_t*>(html_path.c_str()), nullptr, nullptr, nullptr, nullptr); // show options CVerticalLayoutUI* options = static_cast<CVerticalLayoutUI*>(m_PaintManager.FindControl(L"options")); if (!options)return; options->RemoveAll(); std::list<song::Mp3Info::QuizInfo::Quiz::OptionAndContent> list; quiz->get_questions(list); for (auto option_and_content : list) { // add container CHorizontalLayoutUI* container = new CHorizontalLayoutUI(); container->SetFixedHeight(50); options->Add(container); // add option CButtonUI* btn_option = new CButtonUI(); btn_option->SetFixedWidth(50); btn_option->SetFixedWidth(50); std::wstring option = option_and_content.first; btn_option->SetName((BTN_OPTION_PREFIX + option).c_str()); btn_option->SetNormalImage((NORMAL_OPTION_PREFIX + option + POSTFIX_PNG).c_str()); btn_option->SetFocusedImage((NORMAL_OPTION_PREFIX + option + POSTFIX_PNG).c_str()); btn_option->SetHotImage((HOT_OPTION_PREFIX + option + POSTFIX_PNG).c_str()); btn_option->SetPushedImage((HOT_OPTION_PREFIX + option + POSTFIX_PNG).c_str()); container->Add(btn_option); // add content CActiveXUI* content = new CActiveXUI(); container->Add(content); IWebBrowser2* pWebBrwser = nullptr; content->SetDelayCreate(false); // 相当于界面设计器里的DelayCreate属性改为FALSE,在duilib自带的FlashDemo里可以看到此属性为TRUE content->CreateControl(CLSID_WebBrowser); // 相当于界面设计器里的Clsid属性里填入{8856F961-340A-11D0-A96B-00C04FD705A2},建议用CLSID_WebBrowser,如果想看相应的值,请见<ExDisp.h> content->GetControl(IID_IWebBrowser2, (void**)&pWebBrwser); assert(pWebBrwser); if (!pWebBrwser)return; ss.str(L""); ss.clear(); ss << L"<HTML>" L"<head>" L"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" L"<title>lyric</title>" L"</head>" L"<BODY SCROLL=NO bgcolor='#FFFFBF' topmargin='2' leftmargin='2'>" L"<TABLE WIDTH=100% HEIGHT=100%><TR WIDTH=100% HEIGHT=100%><TD style=\"font-family:微软雅黑; font-size:20px; \">" L"<font size='3' color=#000000>" << option_and_content.second << L"</font>" L"</TD></TR></TABLE>" L"</BODY>" L"</HTML>"; std::wstring w = ss.str(); std::string u; utf8::utf16to8(w.begin(), w.end(), std::back_inserter(u)); std::wstring html_path = m_songInfo->get_tmp_path() + L"\\" + m_songInfo->get_id() + L"\\content_" + option + L".html"; std::wofstream out(html_path); if (!out.is_open())return; out << u.c_str(); out.close(); pWebBrwser->Navigate(const_cast<wchar_t*>(html_path.c_str()), nullptr, nullptr, nullptr, nullptr); pWebBrwser->Release(); // add line gap CHorizontalLayoutUI* line_gap = new CHorizontalLayoutUI(); line_gap->SetFixedHeight(50); options->Add(line_gap); } // if user had chosen an answer before, show it. auto user_answer = quiz->get_user_answer(); if (!user_answer.empty()) { std::wstring option_btn_name = BTN_OPTION_PREFIX + user_answer; CButtonUI* btn = static_cast<CButtonUI*>(m_PaintManager.FindControl(option_btn_name.c_str())); if (btn) { g_prev_clicked_button_option = nullptr; UpdateButtonUi2(btn, user_answer); } } g_cur_quiz_info = quiz; ss.str(L""); ss.clear(); ss << ndx; std::wstring question_ndx = ss.str(); std::wstring question_btn_name = BTN_QUESTION_PREFIX + ss.str(); CButtonUI* question_btn = static_cast<CButtonUI*>(m_PaintManager.FindControl(question_btn_name.c_str())); if (question_btn) { g_prev_clicked_button = nullptr; UpdateButtonUi(question_btn, question_ndx); } }
void CDuiFrameWnd::Notify( TNotifyUI& msg ) { if (msg.sType == DUI_MSGTYPE_SELECTCHANGED) { CTreeViewUI* pTree = static_cast<CTreeViewUI*>(m_PaintManager.FindControl(_T("treePlaylist"))); if(pTree && -1 != pTree->GetItemIndex(msg.pSender) && U_TAG_PLAYLIST == msg.pSender->GetTag()) { m_iPlaylistIndex = pTree->GetItemIndex(msg.pSender); Play(m_cPlayList.GetPlaylist(GetPlaylistIndex(m_iPlaylistIndex)).szFileName); //(static_cast<CTreeNodeUI*> (msg.pSender))->GetItemText(); } } else if(msg.sType == DUI_MSGTYPE_SELECTCHANGED) { CDuiString strName = msg.pSender->GetName(); CTabLayoutUI* pTab = static_cast<CTabLayoutUI*>(m_PaintManager.FindControl(_T("tabCaption"))); std::vector<CDuiString> vctString; vctString.push_back(_T("tabPlay")); vctString.push_back(_T("tabLib")); vctString.push_back(_T("tabFind")); vctString.push_back(_T("tabMine")); vctString.push_back(_T("tabCloud")); std::vector<CDuiString>::iterator it = std::find(vctString.begin(), vctString.end(), strName); if (vctString.end() != it) { int iIndex = it - vctString.begin(); pTab->SelectItem(iIndex); // 加载网页 // 由于加载网页会耗很多内存,所以这里选择动态加载 if (iIndex > 0) { std::vector<CDuiString> vctName, vctURL; CActiveXUI* pActiveXUI; vctName.push_back(_T("ActiveXLib")); vctName.push_back(_T("ActiveXFind")); vctName.push_back(_T("ActiveXMine")); vctName.push_back(_T("ActiveXCloud")); vctURL.push_back(_T("http://pianku.xmp.kankan.com/moviestore_index.html")); vctURL.push_back(_T("http://search.xmp.kankan.com/index4xmp.shtml")); vctURL.push_back(_T("http://pianku.xmp.kankan.com/xmpguess/host.html")); vctURL.push_back(_T("http://vod.xunlei.com/page/xmp/home/home.html?init=1")); iIndex--; pActiveXUI = static_cast<CActiveXUI*>(m_PaintManager.FindControl(vctName[iIndex])); if(pActiveXUI) { IWebBrowser2* pWebBrowser = NULL; pActiveXUI->GetControl(IID_IWebBrowser2, (void**)&pWebBrowser); if(pWebBrowser) { _bstr_t bstrTmp; BSTR bstr; pWebBrowser->get_LocationURL(&bstr); bstrTmp.Attach(bstr); if (! bstrTmp.length()) { pWebBrowser->Navigate(_bstr_t(vctURL[iIndex]), NULL,NULL,NULL,NULL); pWebBrowser->Release(); } } } } } } else if(msg.sType == DUI_MSGTYPE_ITEMCLICK) { CDuiString strName = msg.pSender->GetName(); if (strName == _T("menuSequence")) { m_emPlayMode = EM_PLAY_MODE_SEQUENCE; } else if (strName == _T("menuRandom")) { m_emPlayMode = EM_PLAY_MODE_RANDOM; } else if (strName == _T("menuSingleCircle")) { m_emPlayMode = EM_PLAY_MODE_SINGLE_CIRCLE; } } else if( msg.sType == DUI_MSGTYPE_DBCLICK ) { if (IsInStaticControl(msg.pSender)) { // 这里会传进来很多次双击消息,所以只获取祖先控件的消息 if (! msg.pSender->GetParent()) { FullScreen(! m_bFullScreenMode); } } } __super::Notify(msg); }
bool CMyInternetExplorer::FindUsingTitle (const CString & sTitleToSearch) { if (m_pWebBrowser != NULL) { m_pWebBrowser->Release (); m_pWebBrowser = NULL; } HRESULT hr; SHDocVw::IShellWindowsPtr spSHWinds; hr = spSHWinds.CreateInstance (__uuidof(SHDocVw::ShellWindows)); if (FAILED (hr)) return false; ASSERT (spSHWinds != NULL); long nCount = spSHWinds->GetCount (); IDispatchPtr spDisp; for (long i = 0; i < nCount; i++) { _variant_t va (i, VT_I4); spDisp = spSHWinds->Item (va); IWebBrowser2 * pWebBrowser = NULL; hr = spDisp.QueryInterface (IID_IWebBrowser2, & pWebBrowser); if (pWebBrowser != NULL) { HRESULT hr; IDispatch* pHtmlDocDispatch = NULL; IHTMLDocument2 * pHtmlDoc = NULL; // Retrieve the document object. hr = pWebBrowser->get_Document (&pHtmlDocDispatch); if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL)) { // Query for IPersistStreamInit. hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2, (void**)&pHtmlDoc); if (SUCCEEDED (hr) && (pHtmlDoc != NULL)) { CString sTitle; HWND hWnd = NULL; pWebBrowser->get_HWND ((long*)(&hWnd)); if (::IsWindow (hWnd)) { int nLen = ::GetWindowTextLength (hWnd); ::GetWindowText (hWnd, sTitle.GetBufferSetLength (nLen), nLen + 1); sTitle.ReleaseBuffer (); } // If I cannot get the window title (should never happen though) // So, lets just use the title of the document if (sTitle.IsEmpty ()) { BSTR bstrTitle; hr = pHtmlDoc->get_title (&bstrTitle); if (!FAILED (hr)) { sTitle = bstrTitle; SysFreeString (bstrTitle); } } if (StringHelper::WildcardCompareNoCase (sTitleToSearch, sTitle)) { m_pWebBrowser = pWebBrowser; pHtmlDoc->Release (); pHtmlDocDispatch->Release (); // Exit the method safely! return true; } pHtmlDoc->Release(); } pHtmlDocDispatch->Release (); } pWebBrowser->Release (); } } return false; }