网页快照

hScreenDC = ::GetDC(NULL); hMemDC = CreateCompatibleDC(hScreenDC); hBitmap = CreateCompatibleBitmap(GetDC()->m_hDC, 176, 144); oldhBitmap=(HBITMAP)SelectObject(hMemDC, hBitmap);

 

 

HRESULT hr; CComPtr< IUnknown > pUnk = m_Web.GetControlUnknown(); CComPtr< IWebBrowser2 > pBrowser; long m_old_width; long m_old_height; hr =pUnk->QueryInterface(IID_IWebBrowser,(void **)&pBrowser); pBrowser->put_Visible(FALSE); //获取页面宽度和高度 pBrowser->get_Width(&m_old_width); pBrowser->get_Height(&m_old_height); CComPtr< IViewObject > pViewObject; hr = pUnk->QueryInterface(IID_IViewObject,(void **)&pViewObject); CComPtr< IHTMLDocument2 > pDoc; pBrowser->get_Document((IDispatch **)&pDoc); if (pDoc==NULL) return; ASSERT(pDoc); CComPtr< IHTMLElement > pHtml; pDoc->get_body(&pHtml); ASSERT(pHtml); // CComPtr< ICustomDoc > pCustomDoc=NULL; // HRESULT hresult = pDoc->QueryInterface(IID_ICustomDoc, (void**)&pCustomDoc); // ASSERT(pCustomDoc); // hr=pCustomDoc->SetUIHandler(m_ui); CComPtr< IHTMLElement > pElement = NULL; hr = pHtml->QueryInterface(IID_IHTMLElement,(void**)&pElement); ASSERT( pElement ); CComPtr< IHTMLStyle > spHTMLStyle = NULL; pElement->get_style(&spHTMLStyle); ASSERT( spHTMLStyle ); //去掉边框 //spHTMLStyle->put_border(CComBSTR(L"none")); CComPtr< IHTMLBodyElement > pBody= NULL; pHtml->QueryInterface(IID_IHTMLBodyElement, (LPVOID *)(&pBody)); ASSERT(pBody); //设置没有滚动条 必须在载入完成后设置 //hr =pBody->put_scroll(CComBSTR(L"no")); IHTMLTextContainer *pCont= NULL; pHtml->QueryInterface(IID_IHTMLTextContainer, (LPVOID *)(&pCont)); ASSERT(pCont); // 获得滚动条高度 long m_height; if(FAILED(pCont->get_scrollHeight( &m_height ))) AfxMessageBox("get get_scrollHeight failed."); //设置滚动条的Top的位置 //static long top=0; //top++; //pCont->put_scrollTop(top); // 获得滚动条宽度 long m_width; if(FAILED(pCont->get_scrollWidth( &m_width ))) AfxMessageBox("get scrollWidth failed."); RECTL rect; rect.left = 0; rect.top = 0; rect.right = 176+20; rect.bottom = 144+20; pBrowser->put_Width(176+20); pBrowser->put_Height(144+20); // oldhBitmap=(HBITMAP)SelectObject(hMemDC, hBitmap); hr = pViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, hScreenDC, hMemDC, &rect, NULL,NULL, 0); // SelectObject(hMemDC,oldhBitmap);

你可能感兴趣的:(网页快照)