void CIncrementSystemBFDlg::OnDocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT FAR* URL) { DocumentCompleteExplorerSelectItem(pDisp, URL); // TODO: Add your control notification handler code here IDispatch * pDocDisp = NULL; // get the DOM IHTMLDocument2 *pDoc=NULL; pDocDisp = m_MyIE.GetDocument(); if (pDocDisp != NULL) { // Obtained the document object by specifying the IHTMLDocument2 Interface. HRESULT hr= pDocDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc ); IHTMLElement* pBody = NULL; BSTR bstrBody; pDoc->get_body(&pBody); pBody->get_innerHTML(&bstrBody); if ( SUCCEEDED(hr) ) { // Obtained the IHTMLDocument2 interface for the document object IHTMLElementCollection* pElemColl = NULL; hr = pDoc->get_all( &pElemColl ); if ( SUCCEEDED(hr) )//ec { CComDispatchDriver spScript; pDoc->get_Script(&spScript); CComVariant var(static_cast<IDispatch*>(new CMyEventSink)); //spScript.Invoke1(L"SaveCppObject", &var); // Obtained element collection. /* #define LOGON_HTML_ID _T("Logon") #define HTTP1_HTML_ID _T("Http1") #define AUTH_HTML_ID _T("Authentication") #define QUERYPT_HTML_ID _T("QueryPhoneType") #define QUERYPOP_HTML_ID _T("QueryPopup") #define QUERYPHONE_HTML_ID _T("QueryPhone") #define HB_HTML_ID _T("Heartbeat") #define RESETPWD_HTML_ID _T("ResetPassword") #define LOGOFF_HTML_ID _T("Logoff") */ // buttonChangePassword querySerialNumber ProcessElementCollection( pElemColl, "querySerialNumber"); } } //ProcessDocument( pDocDisp ); } pDocDisp->Release(); }
void CMFCApplication2View::OnDocumentComplete(LPCTSTR lpszURL) { CHtmlView::OnDocumentComplete(lpszURL); if (lpszURL != nullptr) { CString strURL(lpszURL); static int i = 0; if (strURL.Find(_T("127.0.0.1.com/?code=")) > 0 && i == 0) { CString strCode = strURL.Mid(strURL.Find(_T("127.0.0.1.com/?code="))+20); CString strNewURL(_T("https://api.ciscospark.com/v1/access_token")); CString strPostData(_T("grant_type=authorization_code&client_id=Ce07a320a3e5fd132ac55854ef107e48988fb573b0478c4126df9f01d941a3ec3&client_secret=ec699f8e1f970a7b4e76b06ca226e1d5e3a5c40ee509cacbda2f6d1da7662b67&redirect_uri=http%3A%2F%2F127.0.0.1.com&code=")); strPostData.Append(strCode); Navigate2(strNewURL, NULL, NULL, NULL, (LPVOID)(LPCTSTR)strPostData, (DWORD)strPostData.GetLength()); i++; } if (i == 1) { LPDISPATCH lpDispatch; lpDispatch = GetHtmlDocument(); ASSERT(lpDispatch); CComQIPtr <IHTMLDocument2, &IID_IHTMLDocument2> pDoc2; HRESULT hr; hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc2); if (SUCCEEDED(hr)) { IHTMLElement *pBodyElement; pDoc2->get_body(&pBodyElement); BSTR body; pBodyElement->get_innerHTML(&body); char * strBody = ::_com_util::ConvertBSTRToString(body); pDoc2.Release(); } lpDispatch->Release(); } } }
bool CMyInternetExplorer::FindElement (bool bExactMatch, bool bWildcardMatch, bool bCaseSensitive, bool bClick, bool bTagName, bool bOuterHTML, bool bInnerHTML, bool bTooltip, LPCTSTR sTagNameOrg, LPCTSTR sOuterHTMLOrg, LPCTSTR sInnerHTMLOrg, LPCTSTR sTooltipOrg, CString & sRetTagName, CString & sRetOuterHTML, CString & sRetInnerHTML, CString & sRetTooltip) { ASSERT (m_pWebBrowser != NULL); if (m_pWebBrowser == NULL) return false; HRESULT hr; IDispatch* pHtmlDocDispatch = NULL; IHTMLDocument2 * pHtmlDoc = NULL; bool bSearch = true; // Retrieve the document object. hr = m_pWebBrowser->get_Document (&pHtmlDocDispatch); if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL)) { hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2, (void**)&pHtmlDoc); if (SUCCEEDED (hr) && (pHtmlDoc != NULL)) { IHTMLElementCollection* pColl = NULL; hr = pHtmlDoc->get_all (&pColl); if (SUCCEEDED (hr) && (pColl != NULL)) { CString sTagName (sTagNameOrg), sOuterHTML (sOuterHTMLOrg), sInnerHTML (sInnerHTMLOrg), sTooltip (sTooltipOrg); if (!bCaseSensitive) { sTagName.MakeLower (); sOuterHTML.MakeLower (); sInnerHTML.MakeLower (); sTooltip.MakeLower (); } // Obtained the Anchor Collection... long nLength = 0; pColl->get_length (&nLength); for (int i = 0; i < nLength && bSearch; i++) { COleVariant vIdx ((long)i, VT_I4); IDispatch* pElemDispatch = NULL; IHTMLElement * pElem = NULL; hr = pColl->item (vIdx, vIdx, &pElemDispatch); if (SUCCEEDED (hr) && (pElemDispatch != NULL)) { hr = pElemDispatch->QueryInterface(IID_IHTMLElement, (void**)&pElem); if (SUCCEEDED (hr) && (pElem != NULL)) { BSTR bstrTagName, bstrOuterHTML, bstrInnerHTML, bstrTooltip; CString sTempTagName, sTempOuterHTML, sTempInnerHTML, sTempTooltip; if (!FAILED (pElem->get_tagName (&bstrTagName))) { sTempTagName = bstrTagName; SysFreeString (bstrTagName); } if (!FAILED (pElem->get_outerHTML (&bstrOuterHTML))) { sTempOuterHTML = bstrOuterHTML; SysFreeString (bstrOuterHTML); } if (!FAILED (pElem->get_innerHTML (&bstrInnerHTML))) { sTempInnerHTML = bstrInnerHTML; SysFreeString (bstrInnerHTML); } if (!FAILED (pElem->get_title (&bstrTooltip))) { sTempTooltip = bstrTooltip; SysFreeString (bstrTooltip); } sRetTagName = sTempTagName; sRetOuterHTML = sTempOuterHTML; sRetInnerHTML = sTempInnerHTML; sRetTooltip = sTempTooltip; if (!bCaseSensitive) { sTempTagName.MakeLower (); sTempOuterHTML.MakeLower (); sTempInnerHTML.MakeLower (); sTempTooltip.MakeLower (); } // Do the comparison here! bool bMatches = true; if (bMatches && bTagName) { if (bExactMatch) { if (sTempTagName != sTagName) bMatches = false; } else if (bWildcardMatch) { if (bCaseSensitive) { if (!StringHelper::WildcardCompareNoCase (sTagName, sTempTagName)) bMatches = false; } else { if (!StringHelper::WildcardCompare (sTagName, sTempTagName)) bMatches = false; } } // Just locate the text inside! else { if (sTempTagName.Find (sTagName) == -1) bMatches = false; } } if (bMatches && bOuterHTML) { if (bExactMatch) { if (sTempOuterHTML != sOuterHTML) bMatches = false; } else if (bWildcardMatch) { if (bCaseSensitive) { if (!StringHelper::WildcardCompareNoCase (sOuterHTML, sTempOuterHTML)) bMatches = false; } else { if (!StringHelper::WildcardCompare (sOuterHTML, sTempOuterHTML)) bMatches = false; } } // Just locate the text inside! else { if (sTempOuterHTML.Find (sOuterHTML) == -1) bMatches = false; } } if (bMatches && bInnerHTML) { if (bExactMatch) { if (sTempInnerHTML != sInnerHTML) bMatches = false; } else if (bWildcardMatch) { if (bCaseSensitive) { if (!StringHelper::WildcardCompareNoCase (sInnerHTML, sTempInnerHTML)) bMatches = false; } else { if (!StringHelper::WildcardCompare (sInnerHTML, sTempInnerHTML)) bMatches = false; } } // Just locate the text inside! else { if (sTempInnerHTML.Find (sInnerHTML) == -1) bMatches = false; } } if (bMatches && bTooltip) { if (bExactMatch) { if (sTempTooltip != sTooltip) bMatches = false; } else if (bWildcardMatch) { if (bCaseSensitive) { if (!StringHelper::WildcardCompareNoCase (sTooltip, sTempTooltip)) bMatches = false; } else { if (!StringHelper::WildcardCompare (sTooltip, sTempTooltip)) bMatches = false; } } // Just locate the text inside! else { if (sTempTooltip.Find (sTooltip) == -1) bMatches = false; } } // Done with the comparisons! if (bMatches) { //if (IDCANCEL == AfxMessageBox (_T ("Tag: ") + sTempTagName + _T ("\r\nOuter: ") + sTempOuterHTML + _T ("\r\nInner: ") + sTempInnerHTML + _T ("\r\nTooltip: ") + sTempTooltip, MB_OKCANCEL)) // bSearch = false; // No need to search more! bSearch = false; if (bClick) pElem->click (); } pElem->Release (); } pElemDispatch->Release (); } } pColl->Release (); } pHtmlDoc->Release(); } pHtmlDocDispatch->Release (); } sRetTagName.Empty (); sRetOuterHTML.Empty (); sRetInnerHTML.Empty (); sRetTooltip.Empty (); if (bSearch == false) return true; return false; }
void CWebDlg::OnDocumentComplete(LPDISPATCH pDisp, VARIANT FAR* URL) { IHTMLDocument2* pHTMLDocument2; LPDISPATCH lpDispatch; lpDispatch = m_explore.GetDocument(); if (lpDispatch) { HRESULT hr; hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*) &pHTMLDocument2); lpDispatch->Release(); if (FAILED(hr)) return; if (pHTMLDocument2 == NULL) return; IHTMLElement* pBody; hr = pHTMLDocument2->get_body(&pBody); if (FAILED(hr)) return; if (pBody == NULL) return; BSTR bstr; pBody->get_innerHTML(&bstr); CString csSourceCode(bstr); CString csAction; CString csComment; SysFreeString(bstr); pBody->Release(); if(csSourceCode.Find("newlogin") != -1) { // Authentication not ok ! APP.m_bAuthGame = FALSE; APP.m_bAuthWeb = FALSE; ((CNel_launcherDlg*)AfxGetMainWnd())->m_wndTabs.DestroyWindow(); DestroyWindow(); ((CNel_launcherDlg*)AfxGetMainWnd())->Login(); return; } // ACE: BADDDDDD!!!! the good web page can contains 404 in the cookie because the cookie contains any number we want /* else if(csSourceCode.Find("404") != -1) { // Authentication lost, try to redo the authentication CLoginDlg dlg; dlg.AuthWeb(); OpenUrl(m_csUrl); return; } */ int iFindAction1 = csSourceCode.Find("<!--nel"); int iFindAction2; int iFindComment1; int iFindComment2; if(iFindAction1 != -1) { iFindAction1 = csSourceCode.Find('"', iFindAction1); if(iFindAction1 != -1) { iFindAction2 = csSourceCode.Find('"', iFindAction1+1); if(iFindAction2 != -1) { csAction = csSourceCode.Mid(iFindAction1+1, iFindAction2 - iFindAction1-1); iFindComment1 = iFindAction2 + 2; if(iFindComment1 != -1) { iFindComment2 = csSourceCode.Find("-->", iFindAction1); if(iFindComment2 != -1) { csComment = csSourceCode.Mid(iFindComment1, iFindComment2 - iFindComment1); csComment.TrimRight(); csComment.TrimLeft(); if(csAction == "launch") ((CNel_launcherDlg*)GetParent())->launch(csComment); else if(csAction == "patch") ((CNel_launcherDlg*)GetParent())->patch(csComment); } } } } } } // m_dlgLoading.ShowWindow(SW_HIDE); }
BOOL CHtmlViewer::SaveAs(TCHAR* FileName) { if (this->pIWebBrowser==NULL) return FALSE; BOOL bSuccess=FALSE; // this->pIWebBrowser->ExecWB(OLECMDID_SAVEAS,...) troubles : // don't get updated content // don't update res:// links) // this saving way troubles : don't save remote files only res and file protocols supported CHtmlViewerSave_FirstItem FirstItem; HRESULT hr; HANDLE hFile; IDispatch* pHtmlDocDispatch = NULL; IHTMLDocument3* pHtmlDoc = NULL; // Retrieve the document object. hr = pIWebBrowser->get_Document(&pHtmlDocDispatch); if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL)) { hr = pHtmlDocDispatch->QueryInterface(IID_IHTMLDocument3,(void**)&pHtmlDoc); if (SUCCEEDED (hr) && (pHtmlDoc != NULL)) { IHTMLElement* pElem = NULL; hr = pHtmlDoc->get_documentElement(&pElem); if (SUCCEEDED (hr) && (pElem != NULL)) { BSTR bstrDocContent; pElem->get_innerHTML(&bstrDocContent); TCHAR* pDocContent; TCHAR* pszCurrent; TCHAR* pszResProtocol; TCHAR* pszResProtocolEnd; TCHAR* pszFileProtocol; TCHAR* pszFileProtocolEnd; TCHAR* pszDontSaveBegin; TCHAR* pszDontSaveEnd; TCHAR* pszMin; TCHAR* psz; TCHAR Link[MAX_PATH]; TCHAR ChangedLink[MAX_PATH]; #if (defined(UNICODE)||defined(_UNICODE)) pDocContent=bstrDocContent; #else CAnsiUnicodeConvert::UnicodeToAnsi(bstrDocContent,&pDocContent); #endif if (CTextFile::CreateTextFile(FileName,&hFile)) { CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_HEADER); pszCurrent=pDocContent; for (;;) { // find next dont save begin pszDontSaveBegin=_tcsstr(pszCurrent,CHtmlViewer_DONT_SAVE_BEGIN); // find next file:// protocol pszFileProtocol=_tcsstr(pszCurrent,CHtmlViewer_FILE_PROTOCOL); // find next res:// protocol (like "res://foo.exe/jpg/105") pszResProtocol=_tcsstr(pszCurrent,CHtmlViewer_RES_PROTOCOL); // if no more res::// protocol, file:// protocol or <!--DONT_SAVE_BEGIN--> if ((pszResProtocol==NULL) && (pszFileProtocol==NULL) && (pszDontSaveBegin==NULL) ) { CTextFile::WriteText(hFile,pszCurrent); break; } // at least one item is not null // get first not null item if (pszDontSaveBegin) pszMin=pszDontSaveBegin; else pszMin=(TCHAR*)-1; FirstItem=CHtmlViewerSave_FirstItem_DontSave; if ((pszFileProtocol<pszMin) && (pszFileProtocol!=0) ) { FirstItem=CHtmlViewerSave_FirstItem_File; pszMin=pszFileProtocol; } if ((pszResProtocol<pszMin) && (pszResProtocol!=0) ) { FirstItem=CHtmlViewerSave_FirstItem_Res; pszMin=pszResProtocol; } // do treatment for first found type // (use if instead case to allow breaking for(;;). Else we need a goto) if (FirstItem==CHtmlViewerSave_FirstItem_Res) { // write data before res:// protocol CTextFile::WriteText(hFile,pszCurrent,pszResProtocol-pszCurrent+1); // look for the end of res:// protocol pszResProtocolEnd=_tcschr(pszResProtocol+_tcslen(CHtmlViewer_RES_PROTOCOL),'"'); if (!pszResProtocolEnd) { // bad html format, output raw content SetFilePointer(hFile,0,0,FILE_BEGIN); CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_HEADER); CTextFile::WriteText(hFile,pDocContent); break; } _tcsncpy(Link,pszResProtocol,pszResProtocolEnd-pszResProtocol+1); Link[pszResProtocolEnd-pszResProtocol+1]=0; // change link from resource one to extracted resource one this->ModifyLinkAndExtractResource(FileName,Link,ChangedLink); // write modified link CTextFile::WriteText(hFile,ChangedLink); // end link by adding '"' CTextFile::WriteText(hFile,_T("\"")); // pointer after res protocol pszCurrent=pszResProtocolEnd+1; } else if (FirstItem==CHtmlViewerSave_FirstItem_File) { // write data before file:// protocol CTextFile::WriteText(hFile,pszCurrent,pszFileProtocol-pszCurrent+1); // look for the end of file:// protocol pszFileProtocolEnd=_tcschr(pszFileProtocol+_tcslen(CHtmlViewer_FILE_PROTOCOL),'"'); if (!pszFileProtocolEnd) { // bad html format, output raw content SetFilePointer(hFile,0,0,FILE_BEGIN); CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_HEADER); CTextFile::WriteText(hFile,pDocContent); break; } pszFileProtocol+=_tcslen(CHtmlViewer_FILE_PROTOCOL); _tcsncpy(Link,pszFileProtocol,pszFileProtocolEnd-pszFileProtocol); Link[pszFileProtocolEnd-pszFileProtocol]=0; // get saving filename _tcscpy(ChangedLink,FileName); // remove file extension of saving file name CStdFileOperations::RemoveFileExt(ChangedLink); // add "_files\" to saving file to create a directory like SavingFileName_files _tcscat(ChangedLink,CHtmlViewer_FILES_DIR_EXT); // add the name of file _tcscat(ChangedLink,CStdFileOperations::GetFileName(Link)); // create directory if necessary CStdFileOperations::CreateDirectoryForFile(ChangedLink); // copy file to directory CopyFile(Link,ChangedLink,FALSE); // now make a relative link to file _tcscpy(Link,ChangedLink); psz=_tcsrchr(Link,'\\'); if (psz) { *psz='/'; psz=_tcsrchr(Link,'\\'); if (psz) { _tcscpy(ChangedLink,psz+1); } } // write modified link CTextFile::WriteText(hFile,ChangedLink); // end link by adding '"' CTextFile::WriteText(hFile,_T("\"")); // pointer after file protocol pszCurrent=pszFileProtocolEnd+1; } else if (FirstItem==CHtmlViewerSave_FirstItem_DontSave) { // write data before <!--DONT_SAVE_BEGIN--> CTextFile::WriteText(hFile,pszCurrent,pszDontSaveBegin-pszCurrent); pszDontSaveEnd=_tcsstr(pszDontSaveBegin+_tcslen(CHtmlViewer_DONT_SAVE_BEGIN),CHtmlViewer_DONT_SAVE_END); if (!pszDontSaveEnd) { // bad html format, output raw content SetFilePointer(hFile,0,0,FILE_BEGIN); CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_HEADER); CTextFile::WriteText(hFile,pDocContent); break; } // point after <!--DONT_SAVE_END--> pszCurrent=pszDontSaveEnd+_tcslen(CHtmlViewer_DONT_SAVE_END); } } CTextFile::WriteText(hFile,CHtmlViewer_DOCUMENT_FOOTER); CloseHandle(hFile); bSuccess=TRUE; } #if ((!defined(UNICODE))&& (!defined(_UNICODE))) // free allocated string for ansi free(pDocContent); #endif SysFreeString(bstrDocContent); pElem->Release(); } pHtmlDoc->Release(); } pHtmlDocDispatch->Release(); } return bSuccess; }