[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)

 

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

 

Simple code example:

Ihtmldocument3 * pdoc = ...; // obtain the ihtmldocument3 pointer <br/> ihtmlelement * pdocelement = NULL; <br/> pdoc-> get_documentelement (& pdocelement); <br/> ihtmlelementrender * Prender = NULL; <br/> pdocelement-> QueryInterface (iid_ihtmlelementrender, (void **) & Prender); <br/> pdocelement-> drawtodc (himagedc); </P> <p>

 

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:

Ihtmldocument2 * pdoc = ...; // obtain the ihtmldocument2 pointer <br/> iviewobject * pviewobject = NULL; <br/> pdoc-> QueryInterface (iid_iviewobject, (void **) pviewobject ); <br/> pviewobject-> (dvaspect_content, 1, null, null, hscreendc, himagedc, rcsource, null, null, 0); </P> <p>

 

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:

Iwebbrowser2 * piwebbrowser2 = ...; // obtain the iwebbrowser2 pointer <br/> hwnd htridentwnd = NULL; <br/> iolewindow * polewin = NULL; <br/> piwebbrowser2-> QueryInterface (iid_ppv_args (& polewin )); <br/> polewin-> getwindow (& htridentwnd); // get the Trident window handle (Class Name "Internet assumer_server") <br/>: printwindow (htridentwnd, himagedc, pw_clientonly); </P> <p>

 

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.

 

 

> Original article copyright belongs to the author, reprint please indicate the source (http://blog.csdn.net/WinGeek/), thank you. <

 

 

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.