用API获得Internet Explorer_Server类的HTML

  

  首先要找到含有Internet Explorer_Server类句柄,

  HTMLDocumentClass  result = (HTMLDocumentClass)documentFromDOM(hWnd.ToInt32());

  result.activeElement.innerHTML就得到所有HTML

 

  

private static IHTMLDocument2 documentFromDOM(int hWnd)
        {
             IHTMLDocument2 document=null;

            int lRes=0;
            int lngMsg = NativeMethods.RegisterWindowMessage("WM_HTML_GETOBJECT");
            Guid IID_IHTMLDocument = new Guid("626FC520-A41E-11CF-A731-00A0C9082637");
            if (lngMsg != 0)
            {
                NativeMethods.SendMessageTimeout(hWnd, lngMsg, 0, 0, NativeMethods.SMTO_ABORTIFHUNG, 1000, ref lRes);
                if (!(bool)(lRes == 0))
                {
                    int hr = NativeMethods.ObjectFromLresult(lRes, ref IID_IHTMLDocument, 0, ref document);
                    if ((bool)(document == null))
                    {
                        MessageBox.Show("No IHTMLDocument Found!", "Warning");
                    }
                }
            }


            return document;
        }

 

 

posted @ 2010-05-15 09:41  alex hu  阅读(1044)  评论(0编辑  收藏  举报