C # show you how to get the document object from the IE window step by step

Source: Internet
Author: User
1. Use Win32 API or UI Atomation to obtain the window. The window type is "Internet assumer_server" 2. Add reference: MSHTML, SHDocVw (Microsoft Internet Controls), Accessibility 3. Import API AccessibleObjectFromWindow: You can refer to pInvoke.net for more useful information. 4. Get Acc from the window: (hienative?whandle is the window pointer obtained in step 1)

           object objAcc = null;
Guid guidAcc = typeof( IAccessible).GUID;
AccessibilityAPI.AccessibleObjectFromWindow( (IntPtr)hIENativeWindowHandle,
0,
ref guidAcc,
ref objAcc);
IAccessible oAccIE = objAcc as IAccessible;

5. Get IServiceProvider

 IServiceProvider oServiceProvider = oAccIE as IServiceProvider
6. Take Document
                   object objHTMLWin2 = null;
Guid guidHTML2 = typeof(mshtml.IHTMLWindow2).GUID;
oServiceProvider.QueryService(ref guidHTML2, ref guidHTML2, out objHTMLWin2 )
IHTMLWindow2 oIEWin2 = objHTMLWin2 as IHTMLWindow2;
IHTMLDocument2 docRoot = oIEWin2.document as IHTMLDocument2;
The above code is passed on VS 2008 and Vista.

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.