// 해당 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); }
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")); } }
void go( const char *url ){ wchar_t *buf; int sz=MultiByteToWideChar( CP_ACP,0,url,-1,0,0 ); buf=new wchar_t[sz]; MultiByteToWideChar( CP_ACP,0,url,-1,buf,sz ); BSTR bstr=SysAllocString(buf); emitNavEvent=false; iBrowser->Navigate( bstr,0,0,0,0 ); SysFreeString(bstr); delete[] buf; }
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; }
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; }
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 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)); } }
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); }