• <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>

            把握命運,追逐夢想

            對自己所做的事要有興趣,同時還要能夠堅持不懈

            統計

            留言簿(1)

            閱讀排行榜

            評論排行榜

            整理一下網上的那個vc遍歷網頁的程序

            #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();              
            //等待回車    
               
                
            return 0;  

            }


            void EnumIE( void )   
            {   
                wcout
            <<_T("開始掃描系統中正在運行的瀏覽器實例")<<endl;   
               
                CComPtr
            <IShellWindows> spShellWin;   
                HRESULT hr 
            = spShellWin.CoCreateInstance( CLSID_ShellWindows );   
                
            if ( FAILED ( hr ) )   
                
            {   
                    wcout 
            <<_T("獲取 IShellWindows 接口錯誤")<<endl;   
                    
            return;   
                }
               
               
                
            long nCount = 0;        // 取得瀏覽器實例個數(Explorer 和 IExplorer)    
                spShellWin->get_Count( &nCount );   
                
            if0 == nCount )   
                
            {   
                    wcout
            <<_T("沒有在運行著的瀏覽器")<<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;   
               
                    
            // 程序運行到此,已經找到了 IHTMLDocument2 的接口指針    
               
                    
            // 刪除下行語句的注釋,把瀏覽器的背景改變看看    
                    
            // 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;             //取得子框架個數    
                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 );//取得子框架的自動化接口" 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 );         
            //遞歸枚舉當前子框架 IHTMLDocument2 上的表單form    
                }
               
            }
               
               
            void EnumForm( IHTMLDocument2 * pIHTMLDocument2 )   
            {   
                
            if!pIHTMLDocument2 )  return;   
               
                EnumFrame( pIHTMLDocument2 );   
            //遞歸枚舉當前 IHTMLDocument2 上的子框架fram    
               
                HRESULT hr;   
                CComBSTR bstrTitle;   
                pIHTMLDocument2
            ->get_title( &bstrTitle );    //取得文檔標題    
               
                USES_CONVERSION;   
                wcout 
            << _T("===================="<< endl;   
                wcout 
            << _T("開始枚舉“"<< OLE2CT( bstrTitle ) << _T("”的表單"<< endl;   
                wcout 
            << _T("===================="<< endl;   
               
                CComQIPtr
            < IHTMLElementCollection > spElementCollection;   
                hr 
            = pIHTMLDocument2->get_forms( &spElementCollection ); //取得表單集合    
                if ( FAILED( hr ) )   
                
            {   
                    wcout 
            << _T("獲取表單的集合 IHTMLElementCollection 錯誤"<< endl;   
                    
            return;   
                }
               
               
                
            long nFormCount=0;              //取得表單數目    
                hr = spElementCollection->get_length( &nFormCount );   
                
            if ( FAILED( hr ) )   
                
            {   
                    wcout 
            << _T("獲取表單數目錯誤"<< endl;   
                    
            return;   
                }
               
                   
                
            for(long i=0; i<nFormCount;  i++)//"" 項表單 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;          //取得表單中 域 的數目    
                    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;   //取得第 項表單域
               
                        CComVariant vName,vVal,vType;       
            //取得表單域的 名,值,類型    
                        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");   //未知類型    
               
                        wcout 
            << _T("["<< lpType << _T("");   
                        wcout 
            << lpName << _T(" = "<< lpVal << endl;   
                    }
               
                    
            //想提交這個表單嗎?刪除下面語句的注釋吧    
                    
            //pForm->submit();    
                }
               
            }
              


            posted on 2009-08-10 17:40 把握命運 閱讀(885) 評論(0)  編輯 收藏 引用

            99久久国产亚洲高清观看2024| 狠狠色丁香久久综合婷婷| 免费精品久久久久久中文字幕| 精品久久久久一区二区三区| 久久综合偷偷噜噜噜色| 午夜欧美精品久久久久久久| 久久综合给久久狠狠97色| 国产激情久久久久影院老熟女| 人妻丰满?V无码久久不卡| 久久久无码精品亚洲日韩蜜臀浪潮 | 国产香蕉久久精品综合网| 亚洲精品乱码久久久久久按摩 | 久久综合久久综合久久| 香港aa三级久久三级老师2021国产三级精品三级在 | 久久人人爽人人爽人人av东京热| 久久青青草原综合伊人| 久久婷婷是五月综合色狠狠| 久久亚洲综合色一区二区三区| 思思久久好好热精品国产| 91精品国产91久久| 国产精品久久久天天影视| 亚洲av成人无码久久精品| 伊人色综合久久天天网| 国产成人99久久亚洲综合精品| 亚洲中文字幕无码一久久区| 欧美久久久久久精选9999| 婷婷综合久久狠狠色99h| 精品久久久久久无码中文字幕一区 | 99久久国产综合精品成人影院| 亚洲va久久久噜噜噜久久狠狠| 色综合久久综合网观看| 亚洲欧美国产日韩综合久久| 香港aa三级久久三级| 97精品国产91久久久久久| 麻豆AV一区二区三区久久| 伊人色综合久久天天网| 久久久久久久久久久| 99久久香蕉国产线看观香| 人妻无码精品久久亚瑟影视| 久久久精品人妻一区二区三区蜜桃| 亚洲精品国产综合久久一线|