• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            把握命運(yùn),追逐夢(mèng)想

            對(duì)自己所做的事要有興趣,同時(shí)還要能夠堅(jiān)持不懈

            統(tǒng)計(jì)

            留言簿(1)

            閱讀排行榜

            評(píng)論排行榜

            整理一下網(wǎng)上的那個(gè)vc遍歷網(wǎng)頁(yè)的程序

            #include <stdio.h>
            #include 
            <tchar.h>
            #include
            <iostream>
            #include
            <exdisp.h>
            #include 
            <atlbase.h>  
            #include 
            <atlcom.h>
            #include
            <mshtml.h>

            using namespace std;

            void EnumIE( void );
            void EnumFrame( IHTMLDocument2 * pIHTMLDocument2 ); 
            void EnumForm ( IHTMLDocument2 * pIHTMLDocument2 ); 



            int _tmain(int argc, _TCHAR* argv[])
            {
                wcout.imbue(locale(
            "chs")); 

                ::CoInitialize(NULL);   
            //初始化COM 
               
                EnumIE();               
            //枚舉瀏覽器    
               
                ::CoUninitialize();     
            //釋放COM
               
                wcout
            <<_T("======完成======")<<endl;   
                getchar();              
            //等待回車(chē)    
               
                
            return 0;  

            }


            void EnumIE( void )   
            {   
                wcout
            <<_T("開(kāi)始掃描系統(tǒng)中正在運(yùn)行的瀏覽器實(shí)例")<<endl;   
               
                CComPtr
            <IShellWindows> spShellWin;   
                HRESULT hr 
            = spShellWin.CoCreateInstance( CLSID_ShellWindows );   
                
            if ( FAILED ( hr ) )   
                
            {   
                    wcout 
            <<_T("獲取 IShellWindows 接口錯(cuò)誤")<<endl;   
                    
            return;   
                }
               
               
                
            long nCount = 0;        // 取得瀏覽器實(shí)例個(gè)數(shù)(Explorer 和 IExplorer)    
                spShellWin->get_Count( &nCount );   
                
            if0 == nCount )   
                
            {   
                    wcout
            <<_T("沒(méi)有在運(yùn)行著的瀏覽器")<<endl;   
                    
            return;   
                }
               
               
                
            for(int i=0; i<nCount; i++)
                
            {  
                    CComPtr
            <IDispatch > spDispIE;   
                    hr
            =spShellWin->Item(CComVariant( (long)i ), &spDispIE );   
                    
            if ( FAILED ( hr ) )    continue;   
               
                    CComQIPtr
            <IWebBrowser2> spBrowser = spDispIE;   
                    
            if ( !spBrowser )       continue;   
               
                    CComPtr 
            <IDispatch> spDispDoc;   
                    hr 
            = spBrowser->get_Document( &spDispDoc );   
                    
            if ( FAILED ( hr ) )    continue;   
               
                    CComQIPtr
            < IHTMLDocument2 > spDocument2 = spDispDoc;   
                    
            if ( !spDocument2 )     continue;   
               
                    
            // 程序運(yùn)行到此,已經(jīng)找到了 IHTMLDocument2 的接口指針    
               
                    
            // 刪除下行語(yǔ)句的注釋?zhuān)褳g覽器的背景改變看看    
                    
            // spDocument2->put_bgColor( CComVariant( "green" ) );    
                       
                    EnumForm( spDocument2 );        
            //枚舉所有的表單    
                }
               
            }
               
               
            void EnumFrame( IHTMLDocument2 * pIHTMLDocument2 )   
            {   
                
            if ( !pIHTMLDocument2 ) return;   
               
                HRESULT hr;   
               
                CComPtr
            < IHTMLFramesCollection2 > spFramesCollection2;   
                pIHTMLDocument2
            ->get_frames( &spFramesCollection2 ); //取得框架frame的集合    
               
                
            long nFrameCount=0;             //取得子框架個(gè)數(shù)    
                hr = spFramesCollection2->get_length( &nFrameCount );   
                
            if ( FAILED ( hr ) || 0 == nFrameCount )    return;   
               
                
            for(long i=0; i<nFrameCount;  i++
                
            {
                    CComVariant vDispWin2;
                    hr
            =spFramesCollection2->item( &CComVariant(i), &vDispWin2 );//取得子框架的自動(dòng)化接口" vDispWin2; CComVariant   
                    if ( FAILED ( hr ) )    continue;   
               
                    CComQIPtr
            < IHTMLWindow2 > spWin2 = vDispWin2.pdispVal;   
                    
            if!spWin2 )   continue;   //取得子框架的 IHTMLWindow2 接口    
               
                    CComPtr 
            < IHTMLDocument2 > spDoc2;   
                    spWin2
            ->get_document( &spDoc2 ); //取得字框架的 IHTMLDocument2 接口    
               
                    EnumForm( spDoc2 );         
            //遞歸枚舉當(dāng)前子框架 IHTMLDocument2 上的表單form    
                }
               
            }
               
               
            void EnumForm( IHTMLDocument2 * pIHTMLDocument2 )   
            {   
                
            if!pIHTMLDocument2 )  return;   
               
                EnumFrame( pIHTMLDocument2 );   
            //遞歸枚舉當(dāng)前 IHTMLDocument2 上的子框架fram    
               
                HRESULT hr;   
                CComBSTR bstrTitle;   
                pIHTMLDocument2
            ->get_title( &bstrTitle );    //取得文檔標(biāo)題    
               
                USES_CONVERSION;   
                wcout 
            << _T("===================="<< endl;   
                wcout 
            << _T("開(kāi)始枚舉“"<< OLE2CT( bstrTitle ) << _T("”的表單"<< endl;   
                wcout 
            << _T("===================="<< endl;   
               
                CComQIPtr
            < IHTMLElementCollection > spElementCollection;   
                hr 
            = pIHTMLDocument2->get_forms( &spElementCollection ); //取得表單集合    
                if ( FAILED( hr ) )   
                
            {   
                    wcout 
            << _T("獲取表單的集合 IHTMLElementCollection 錯(cuò)誤"<< endl;   
                    
            return;   
                }
               
               
                
            long nFormCount=0;              //取得表單數(shù)目    
                hr = spElementCollection->get_length( &nFormCount );   
                
            if ( FAILED( hr ) )   
                
            {   
                    wcout 
            << _T("獲取表單數(shù)目錯(cuò)誤"<< endl;   
                    
            return;   
                }
               
                   
                
            for(long i=0; i<nFormCount;  i++)//"" 項(xiàng)表單 i 取得第 ;
                {
                
                    IDispatch  
            *pDisp=NULL;
                     hr
            = spElementCollection->item( CComVariant( i ), CComVariant(i), &pDisp );       
                    
            if ( FAILED( hr ) )     continue;   
               
                    CComQIPtr
            < IHTMLFormElement > spFormElement = pDisp;   
                    pDisp
            ->Release();   
               
                    
            long nElemCount=0;          //取得表單中 域 的數(shù)目    
                    hr = spFormElement->get_length( &nElemCount );   
                    
            if ( FAILED( hr ) )     continue;   
               
                    
            for(long j=0; j<nElemCount;  j++)
                    

                        CComDispatchDriver spInputElement; 
            //  j ; 

                        hr
            =spFormElement->item( CComVariant( j ), CComVariant(), &spInputElement );   
                    
                        
            if ( FAILED( hr ) ) continue;   //取得第 項(xiàng)表單域
               
                        CComVariant vName,vVal,vType;       
            //取得表單域的 名,值,類(lèi)型    
                        hr = spInputElement.GetPropertyByName( L"name"&vName );   
                        
            if( FAILED( hr ) )  continue;   
                        hr 
            = spInputElement.GetPropertyByName( L"value"&vVal );   
                        
            if( FAILED( hr ) )  continue;   
                        hr 
            = spInputElement.GetPropertyByName( L"type"&vType );   
                        
            if( FAILED( hr ) )  continue;   
               
                        LPCTSTR lpName 
            = vName.bstrVal?   
                                OLE2CT( vName.bstrVal ) : _T(
            "NULL");   //未知域名    
                        LPCTSTR lpVal  = vVal.bstrVal?   
                                OLE2CT( vVal.bstrVal  ) : _T(
            "NULL");   //空值,未輸入    
                        LPCTSTR lpType = vType.bstrVal?   
                                OLE2CT( vType.bstrVal ) : _T(
            "NULL");   //未知類(lèi)型    
               
                        wcout 
            << _T("["<< lpType << _T("");   
                        wcout 
            << lpName << _T(" = "<< lpVal << endl;   
                    }
               
                    
            //想提交這個(gè)表單嗎?刪除下面語(yǔ)句的注釋吧    
                    
            //pForm->submit();    
                }
               
            }
              


            posted on 2009-08-10 17:40 把握命運(yùn) 閱讀(884) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            91久久精品国产成人久久| 国产三级精品久久| 99精品国产综合久久久久五月天| 久久男人AV资源网站| 久久精品人妻中文系列| 狠狠干狠狠久久| | 99久久久精品| 久久综合中文字幕| 欧美精品久久久久久久自慰| 精品久久777| 久久综合久久鬼色| 国内精品久久久久| 狠狠色丁香久久婷婷综合图片| 国产精品成人99久久久久| 日日狠狠久久偷偷色综合0| 嫩草影院久久99| 国内精品伊人久久久久妇| 嫩草影院久久国产精品| 精品多毛少妇人妻AV免费久久 | 日产精品久久久久久久| 久久成人影院精品777| 久久久这里有精品| 久久e热在这里只有国产中文精品99| 久久精品国产亚洲av影院| 久久午夜免费视频| 亚洲狠狠综合久久| 久久精品国产久精国产| 麻豆av久久av盛宴av| 久久久久成人精品无码| 久久久久99精品成人片牛牛影视| 熟妇人妻久久中文字幕| 久久国产色AV免费观看| 久久久精品国产免大香伊| 亚洲国产成人久久精品99| 久久久国产亚洲精品| 久久亚洲av无码精品浪潮| 国产精品99久久久久久猫咪 | 国产精品午夜久久| 国产—久久香蕉国产线看观看 | 免费一级欧美大片久久网|