WebBrowser中取對應的圖片資源

來源:互聯網
上載者:User

標籤:style   blog   http   ar   color   os   使用   sp   for   

在用戶端中使用webbrower控制項,控制項中已顯示網頁,對應的圖片資源應已下載完,下面從緩衝中找到圖片資源,兩種方法都可

1、GetUrlCacheEntryInfo

http://msdn.microsoft.com/en-us/library/aa384185(v=vs.85).aspx

2、FindFirstUrlCacheEntry、FindNextUrlCacheEntry、FindCloseUrlCache

http://msdn.microsoft.com/zh-SG/library/aa384026

void CTesthaijiaDlg::OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR szUrl){    if (pDisp == m_pBrowserApp)    {        CString sCheckUrl(szUrl);        if (sCheckUrl.CompareNoCase(sLoginUrl) == 0)        {            if (m_spHtmlDoc)            {                CDispatch disp = m_spHtmlDoc;                disp.InvokePtr(L"getElementById", L"txtUserName").Put(L"value", L"abc");                disp.InvokePtr(L"getElementById", L"txtPassword").Put(L"value", L"abc");                  CDispatch dispImg = disp.InvokePtr(L"getElementById", L"ValidIMG");                 CString s = dispImg.Get(L"src");                if (1)                {                    LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;                    DWORD dwEntrySize = 4096;                    lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];                    lpCacheEntry->dwStructSize = dwEntrySize;                    BOOL b = GetUrlCacheEntryInfo(s, lpCacheEntry, &dwEntrySize);                    CString sPath = lpCacheEntry->lpszLocalFileName;                    RECT rc1;                    SystemParametersInfo(SPI_GETWORKAREA,0,(PVOID)&rc1,0);                    SetWindowPos(NULL, 0, rc1.bottom - 4, 0, 0, SWP_NOSIZE);                                                            CDlgCode dlg;                    dlg.SetPath(sPath);                    if (dlg.DoModal() == IDOK)                    {                        disp.InvokePtr(L"getElementById", L"txtIMGCode").Put(L"value", CComVariant(dlg.m_sCode));                        disp.InvokePtr(L"getElementById", L"BtnLogin").Invoke(L"click");                        SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOSIZE);                    }                }                if (0)                {                    LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;                    HANDLE hCacheDir = NULL;                    DWORD dwTrySize, dwEntrySize = 4096;                    DWORD dwError = ERROR_INSUFFICIENT_BUFFER;                    BOOL bSuccess, bDone = FALSE; //是否已經處理完,初始設為false                    while(!bDone){                        switch(dwError){                        case ERROR_INSUFFICIENT_BUFFER:                                 if(lpCacheEntry)                             {                                delete [] lpCacheEntry;                            }                            lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];                            lpCacheEntry->dwStructSize = dwEntrySize;                            dwTrySize = dwEntrySize;                            if(!hCacheDir)                            {//為空白,說明第一次執行,需要找第一個                                hCacheDir = FindFirstUrlCacheEntry(NULL,lpCacheEntry,&dwTrySize);                                bSuccess = (hCacheDir != NULL);                            }                            else                             {                                bSuccess = FindNextUrlCacheEntry(hCacheDir,lpCacheEntry,&dwTrySize);                            }                            if(!bSuccess){                                dwError = GetLastError();                                dwEntrySize = dwTrySize; //使用得到的新長度                             }                            else                             {                                dwError = ERROR_SUCCESS;                            }                            break;                             //we are done                        case ERROR_NO_MORE_ITEMS:                            bDone = TRUE;                            break;                            //we have got an entry                        case ERROR_SUCCESS:                            if(bSuccess && (NORMAL_CACHE_ENTRY & lpCacheEntry->CacheEntryType))                            { //                                CString sUrl1 = lpCacheEntry->lpszSourceUrlName;                                if (sUrl1.Compare(s) == 0)                                {                                    //處理                                }                                //     CTime lastModified(lpCacheEntry->LastModifiedTime);                                //     CTime lastAccessed(lpCacheEntry->LastAccessTime);                                //a changed cookie - delete it!                                //     if(lastModified >= m_time || lastAccessed >= m_time){                                //const   CString   name   =   lpCacheEntry->lpszSourceUrlName;                                  //const   CString   result   =   lastModified.Format("%I:%M:%S%p   %d   %b   %Y");                                  //MessageBox   (NULL,   name   +   "   last   modified   "   +   result,   "Deleting cookie",   MB_OK);                                  //DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);                            }                            //get ready for next entry                            dwTrySize = dwEntrySize;                            if(!FindNextUrlCacheEntry(hCacheDir,lpCacheEntry,&dwTrySize))                            {                                dwError = GetLastError();                                dwEntrySize = dwTrySize;   //使用得到的新長度                            }                            else                             {                                dwError = ERROR_SUCCESS;                            }                            break;                            //unknown error                        default:                            CString strError; strError.Format(_T("There is an error (%d) when trying deleting temporary internet files.\r\n"),   dwError);                              TRACE(strError);                            bDone = TRUE;                            break;                               if(bDone)                                 break;                            Sleep(10);  if(lpCacheEntry){ delete [] lpCacheEntry; lpCacheEntry = NULL;}                            if(hCacheDir){ FindCloseUrlCache(hCacheDir); hCacheDir = NULL;}                            break;                        }                    }                }            }        }    }    CDHtmlDialog::OnDocumentComplete(pDisp, szUrl);}

 

WebBrowser中取對應的圖片資源

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.