[IE programming] Summary of IE web page screenshot Technology

Source: Internet
Author: User

IE web pages are a classic issue in IE programming. After the release of IE9 beta, I received a lot of questions about this. Recently, I have re-structured the Code related to IE and Windows so that IE9 can be perfectly compatible with the original GDI function when hardware acceleration is enabled. While the memory is still fresh, write a summary for your reference.

Mainly include the following3Interfaces can be used to implement IE web pages.

1) HRESULTIHTMLElementRender: DrawToDC(HDC hDC)

Http://msdn.microsoft.com/en-us/library/aa752273 (VS.85). aspx

Simple code example:

 
 
  1. IHTMLDocument3 * pDoc =...; // get the IHTMLDocument3 pointer
  2. IHTMLElement * pDocElement = NULL;
  3. PDoc-> get_documentElement (& pDocElement );
  4. IHTMLElementRender * pRender = NULL;
  5. PDocElement-> QueryInterface (IID_IHTMLElementRender, (void **) & pRender );
  6. PDocElement-> DrawToDC (hImageDC );
  7.  

Note:In Quirks mode, the documentElement does not exist. Use the BODY element.

Advantages:You can draw a specific HTML element.

Disadvantages:

  • Determine whether it is in Quirks mode, and then decide whether to take the documentElement element or the pointer of the BODY element;
  • The image can only be captured based on the current screen size, but cannot be scaled;
  • In some cases, a webpage may fail when it is composed of frames or an embedded doc/pdf document;

 

2) HRESULTIViewObject: Draw(DWORD dwAspect, LONG lindex, void * pvAspect, DVTARGETDEVICE * ptd, HDC hicTargetDev, HDC hdcDraw, const LPRECTL lprcBounds,
Const LPRECTL lprcWBounds, BOOL (*) (DWORD) pfnContinue, DWORD dwContinue)

Http://msdn.microsoft.com/en-us/library/ms688655 (VS.85). aspx

Simple code example:

 
 
  1. IHTMLDocument2 * pDoc =...; // get the IHTMLDocument2 pointer
  2. IViewObject * pViewObject = NULL;
  3. PDoc-> QueryInterface (IID_IViewObject, (void **) pViewObject );
  4. PViewObject-> (DVASPECT_CONTENT, 1, NULL, NULL, hScreenDC, hImageDC, rcSource, NULL, NULL, 0 );

 Advantages:You can scale the image. IE scales the image based on the input lprcBounds.

Disadvantages:

  • The computation and scaling speed is slow;
  • The visible area of the entire document cannot be captured.
  • Some third-party ActiveX programs do not implement the IViewObject interface, so those ActiveX programs do not appear in it.

 

3) BOOLPrintWindow(Hwnd, HDC hdcBlt, nFlags)

Http://msdn.microsoft.com/en-us/library/dd162869 (VS.85). aspx

Simple code example:

 
 
  1. IWebBrowser2 * pIWebBrowser2 =...; // get the IWebBrowser2 pointer
  2. HWND hTridentWnd = NULL;
  3. IOleWindow * pOleWin = NULL;
  4. PIWebBrowser2-> QueryInterface (IID_PPV_ARGS (& pOleWin ));
  5. POleWin-> GetWindow (& hTridentWnd); // get the Trident window handle (Class Name "Internet assumer_server ")
  6. : PrintWindow (hTridentWnd, hImageDC, PW_CLIENTONLY );

Advantages:The content is complete, even if ActiveX does not implement the IViewObject interface, it will also be.

Disadvantages:

  • The image can only be captured based on the current screen size, but cannot be scaled;
  • Less efficient than IHTMLElementRender: DrawToDC

 

Note:The preceding code examples are simplified. Check the function return value and pointer validity for actual use.

Summary

Considering that PrintWindow is the first choice, simple and complete. If you want to get the scaling result, select IViewObject: Draw. If you want to specify an element, select IHTMLElementRender: DrawToDC.


 

This article from the "IE browser development" blog, please be sure to keep this source http://wingeek.blog.51cto.com/1226974/450216

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.