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.