Enumeral IE all ELEMENT code

zhaozj2021-02-17  53

// - Enumeral IE all Element code

#include "stdafx.h"

#pragma Warning (Disable: 4049) #pragma Warning (Disable: 4192) #pragma Warning (Disable: 4146)

// # import "shdocvw.dll" exclude ( "tagREADYSTATE") # import "shdocvw.dll" // # import "shdocvw.dll" rename_namespace ( "SHELL_WINDOW") // using namespace SHELL_WINDOW; #define SHELL_WINDOW SHDocVw

#include #include #include

#include using namespace std;

INT iElement (htmldocument2ptr sp_doc) {int RET = 0; ccomptr Pcollection;

Do {

COUT << "--- list all ie element ---" << endl; // - failed // if (! successded)) if (! ")) IF (!")) ing (! " & pcollection))))))))))))))))

{COUT << "failed." << endl; break;

INT count = 0; int count = 0; if (! succeeded (pcollection-> get_length)) {cout << "failed." << endl;

For (int i = 0; i

CComPtr spDispatch; if (SUCCEEDED (pCollection-> item (index, index, & spDispatch))) {CComPtr pElement; if (SUCCEEDED (spDispatch-> QueryInterface (__uuidof (IHTMLElement), (void **) & pElement ))) {Count ; ccombstr BSTR;

Pelement-> get_tagname (& bstr); if (bstr.length ()> 0) cout << "tag =" << (char *) _ BSTR_T (BSTR); // << end1

Pelement-> get_innertext (& BSTR); if (bstr.length ()> 0) cout << "/ ttext = << (char *) _ bstr_t (bstr) << endl; else cout <<" / ttext = "< toString (& bstr); if (bstr.length ()> 0) cout << "str =" << (char *) _ BSTR_T (BSTR) << end1

// pelement-> release ();} // spdispatch-> release ();}} // pcollection-> release (); cout << "--- list count = << count <<< | <

RET = count; Break;

WHILE (FALSE);

Return Ret;}

INT Main (int Argc, char * argv []) {cout << "--- Test ---" << endl; // - COM COINITIALIZE (NULL); Do {cout << "--- list all IE window --- "<< endl;

SHELL_WINDOW :: IShellWindowsPtr msp_SHWinds = NULL; HRESULT hr = msp_SHWinds.CreateInstance (__ uuidof (SHELL_WINDOW :: ShellWindows)); ". FAILED" if (! S_OK = hr || NULL == msp_SHWinds) {cout << << endl; break } Int count = 0; int count = msp_shwinds-> getCount (); for (int i = 0; i Item (va); // SHELL_WINDOW :: IWebBrowser2Ptr sp_Browser = sp_Disp; // - OK SHELL_WINDOW :: IWebBrowser2Ptr sp_Browser (sp_Disp); if (! NULL = sp_Browser) {// cout << (char *) sp_Browser-> GetLocationName () << ENDL;

IHTMLDocument2ptr sp_doc (sp_browser-> getDocument ()); if (null! = Sp_doc) {count ;

CCOMBSTR BSTR; sp_doc-> get_title (& bstr); cout << (char *) _ BSTR_T (BSTR) << ENDL;

Static int E = 0; if (0 == e) E = Ilement (sp_doc); sp_doc.release ();} sp_browser.release ();}} msp_shwinds.release ();

COUT << "--- list count =" << count << "---" << endl; break;} while (false); // - com // counitialize (); // - ?? ? OleunInitialize (); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-28683.html

New Post(0)