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:
- IHTMLDocument3 * pDoc =...; // get the IHTMLDocument3 pointer
- IHTMLElement * pDocElement = NULL;
- PDoc-> get_documentElement (& pDocElement );
- IHTMLElementRender * pRender = NULL;
- PDocElement-> QueryInterface (IID_IHTMLElementRender, (void **) & pRender );
- PDocElement-> DrawToDC (hImageDC );
-
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 =...; // get the IHTMLDocument2 pointer
- IViewObject * pViewObject = NULL;
- PDoc-> QueryInterface (IID_IViewObject, (void **) pViewObject );
- 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:
- IWebBrowser2 * pIWebBrowser2 =...; // get the IWebBrowser2 pointer
- HWND hTridentWnd = NULL;
- IOleWindow * pOleWin = NULL;
- PIWebBrowser2-> QueryInterface (IID_PPV_ARGS (& pOleWin ));
- POleWin-> GetWindow (& hTridentWnd); // get the Trident window handle (Class Name "Internet assumer_server ")
- : 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