Exemplo n.º 1
1
        public HtmEdit()
        {
            InitializeComponent();

            #region 初始化WEBBROWSER 必须放这里
            webBrowser1.DocumentText = "";
            webBrowser1.Document.OpenNew(true);
            webBrowser1.Document.Focus();//这句要去掉的话双击HTM文档不全选中文本
            webBrowser1.Document.Write(HTML_TEXT);

            doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
            #endregion

            fontComboBox1.Initialize();
            replace1 = new HtmReplaceDialog(this);
            find1 = new HtmFindDialog(this);
        }
Exemplo n.º 2
0
        private string GetHtmlDocSelectedText(mshtml.IHTMLDocument2 htmlDoc, bool html)
        {
            IHTMLSelectionObject selobj = null;
            IHTMLTxtRange        range  = null;

            if ((htmlDoc == null) || (htmlDoc.selection == null))
            {
                return(string.Empty);
            }

            selobj = htmlDoc.selection as IHTMLSelectionObject;
            if (selobj == null)
            {
                return(string.Empty);
            }

            range = selobj.createRange() as IHTMLTxtRange;
            if (range == null)
            {
                return(string.Empty);
            }

            if (html)
            {
                return(range.htmlText);
            }
            else
            {
                return(range.text);
            }
        }
Exemplo n.º 3
0
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            try
            {
                mshtml.IHTMLDocument2 myDoc = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument;

                (myDoc as HTMLDocumentClass).documentElement.setAttribute("scroll", "yes", 0);

                int ctrlHeight = webBrowser1.Height;
                int ctrlWidth  = webBrowser1.Width;

                //document完整高度
                int heightsize = (int)(myDoc as HTMLDocumentClass).documentElement.getAttribute("scrollHeight", 0);
                int widthsize  = (int)(myDoc as HTMLDocumentClass).documentElement.getAttribute("scrollWidth", 0);

                ////Get Screen Height
                int screenHeight = (int)(myDoc as HTMLDocumentClass).documentElement.getAttribute("clientHeight", 0);
                int screenWidth  = (int)(myDoc as HTMLDocumentClass).documentElement.getAttribute("clientWidth", 0);

                e.ToString();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取MS类型的元素
        /// </summary>
        /// <param name="webbrowser"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static IHTMLElement GetMShtmlByIdJSCD(WebBrowser webbrowser, String id)
        {
            mshtml.IHTMLDocument2 mshtmlHtmlDocument = (IHTMLDocument2)webbrowser.Document.DomDocument;
            List <IHTMLElement>   allMShtml          = ChgHtmlColToMShtmlListJSCD(mshtmlHtmlDocument.all);

            return(allMShtml.Where(c => !String.IsNullOrEmpty(c.id) && c.id.Equals(id)).First());
        }
Exemplo n.º 5
0
        public static bool ClickCheckedRect(IntPtr hwnd, mshtml.IHTMLDocument2 doc, string itemName, string tagStr, string indexStr, ref bool isClick, ref Point fakeMousePoint, ClickEvent clickEvent)
        {
            mshtml.IHTMLElement elem = GetCheckedElement(doc, itemName, tagStr, indexStr);
            bool flag = false;

            if (elem != null)
            {
                flag = true;
                Rectangle elementRect = GetElementRect(doc.body, elem);
                isClick = false;
                if ((elementRect.Width > 0) && (elementRect.Height > 0))
                {
                    Random random = new Random();
                    int    num    = random.Next(elementRect.Width);
                    int    num2   = random.Next(elementRect.Height);
                    SetMousePoint(hwnd, ref fakeMousePoint, elementRect.X + num, elementRect.Y + num2, doc);
                    isClick = isClickElement(hwnd, doc, elem, elementRect.X + num, elementRect.Y + num2, clickEvent);
                }
            }
            if (elem != null)
            {
                Marshal.ReleaseComObject(elem);
            }
            return(flag);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据className和TagName ,下级包含某个Id
        /// </summary>
        /// <param name="webbrowser"></param>
        /// <param name="_className"></param>
        /// <param name="_tagName"></param>
        /// <param name="childId"></param>
        /// <returns></returns>
        public static IHTMLElement GetMShtmlByClassTagNameAndChildrenIdJSCD(WebBrowser webbrowser, String _className, String _tagName, String childId)
        {
            IHTMLElement element = null;

            try
            {
                mshtml.IHTMLDocument2 mshtmlHtmlDocument = (IHTMLDocument2)webbrowser.Document.DomDocument;
                List <IHTMLElement>   allMShtml          = ChgHtmlColToMShtmlListJSCD(mshtmlHtmlDocument.all);
                foreach (IHTMLElement item in allMShtml)
                {
                    if (item != null)
                    {
                        if (!string.IsNullOrEmpty(item.tagName) && item.tagName.ToUpper().Equals(_tagName.ToUpper()) &&
                            !string.IsNullOrEmpty(item.className) && item.className.ToUpper().Equals(_className.ToUpper()))
                        {
                            if (item.outerHTML.Contains(childId))
                            {
                                element = item;
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(element);
        }
Exemplo n.º 7
0
        public static List <IHTMLElement> GetMShtmlByClassTagNameJSCD(WebBrowser webbrowser, String _className, String _tagName = "")
        {
            List <IHTMLElement> elementList = new List <IHTMLElement>();

            try
            {
                mshtml.IHTMLDocument2 mshtmlHtmlDocument = (IHTMLDocument2)webbrowser.Document.DomDocument;
                List <IHTMLElement>   allMShtml          = ChgHtmlColToMShtmlListJSCD(mshtmlHtmlDocument.all);

                foreach (IHTMLElement item in allMShtml)
                {
                    if (item != null)
                    {
                        if (!string.IsNullOrEmpty(item.tagName) && item.tagName.ToUpper().Equals(_tagName.ToUpper()) &&
                            !string.IsNullOrEmpty(item.className) && item.className.ToUpper().Equals(_className.ToUpper()))
                        {
                            elementList.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(elementList);
        }
Exemplo n.º 8
0
        public static mshtml.IHTMLElement2 GetWindowWidthAndHeight(IntPtr hwnd, mshtml.IHTMLDocument2 doc, ref int clientWidth, ref int clientHeight, ref int scrollWidth, ref int scrollHeight)
        {
            HTMLDocumentClass class2 = doc as HTMLDocumentClass;

            mshtml.IHTMLElement2 documentElement = null;
            if (class2 != null)
            {
                documentElement = class2.documentElement as mshtml.IHTMLElement2;
                if (documentElement != null)
                {
                    clientWidth  = documentElement.clientWidth;
                    clientHeight = documentElement.clientHeight;
                }
            }
            else
            {
                Rect lpRect = new Rect();
                documentElement = doc.body as mshtml.IHTMLElement2;
                WindowUtil.GetWindowRect(hwnd, out lpRect);
                if (documentElement != null)
                {
                    clientWidth  = lpRect.Right - lpRect.Left;
                    clientHeight = lpRect.Bottom - lpRect.Top;
                }
            }
            if (documentElement != null)
            {
                scrollWidth  = documentElement.scrollWidth;
                scrollHeight = documentElement.scrollHeight;
            }
            return(documentElement);
        }
Exemplo n.º 9
0
        public static mshtml.IHTMLElement GetInputElement(mshtml.IHTMLDocument2 doc, string itemName, string tagStr, string indexStr)
        {
            mshtml.IHTMLElementCollection o       = (mshtml.IHTMLElementCollection)doc.all.tags("input");
            mshtml.IHTMLElement           element = null;
            ElementTag iD   = ElementTag.ID;
            int        num  = 0;
            int        num2 = 0;

            if (!string.IsNullOrEmpty(indexStr))
            {
                num = WindowUtil.StringToInt(indexStr);
            }
            if ((tagStr != string.Empty) && (tagStr != ""))
            {
                iD = (ElementTag)WindowUtil.StringToInt(tagStr);
            }
            foreach (mshtml.IHTMLElement element2 in o)
            {
                if (IsElementMatch(element2, iD, itemName, ""))
                {
                    if (num2 == num)
                    {
                        element = element2;
                        break;
                    }
                    num2++;
                }
            }
            if (o != null)
            {
                Marshal.ReleaseComObject(o);
            }
            return(element);
        }
Exemplo n.º 10
0
        public static int GetLinkElementIndex(mshtml.IHTMLDocument2 doc, mshtml.IHTMLElement ele, string itemName, string tagStr)
        {
            mshtml.IHTMLElementCollection links;
            int        num       = 0;
            bool       flag      = false;
            ElementTag outerText = ElementTag.outerText;

            if (!string.IsNullOrEmpty(tagStr))
            {
                outerText = (ElementTag)WindowUtil.StringToInt(tagStr);
            }
            if (outerText != ElementTag.src)
            {
                links = doc.links;
                if (links == null)
                {
                    goto Label_00EA;
                }
                foreach (mshtml.IHTMLElement element2 in links)
                {
                    if (IsElementMatch(element2, outerText, itemName, ""))
                    {
                        if (ele == element2)
                        {
                            flag = true;
                            break;
                        }
                        num++;
                    }
                }
            }
            else
            {
                links = doc.images;
                if (links != null)
                {
                    foreach (mshtml.IHTMLElement element in links)
                    {
                        if (IsElementMatch(element, outerText, itemName, ""))
                        {
                            if (ele == element)
                            {
                                flag = true;
                                break;
                            }
                            num++;
                        }
                    }
                    Marshal.ReleaseComObject(links);
                }
                goto Label_00EA;
            }
            Marshal.ReleaseComObject(links);
Label_00EA:
            if (!flag)
            {
                num = 0;
            }
            return(num);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Loads the anchors for a specified html file
        /// </summary>
        /// <param name="fileName">The file name in which anchors are to be retrieved from</param>
        private void LoadAnchors(string fileName)
        {
            WebClient client = new WebClient();

            byte[] data = client.DownloadData(fileName);
            mshtml.HTMLDocumentClass ms = new mshtml.HTMLDocumentClass();
            string strHTML = Encoding.ASCII.GetString(data);

            mshtml.IHTMLDocument2 mydoc = (mshtml.IHTMLDocument2)ms;
            //mydoc.write(!--saved from url=(0014)about:internet -->);
            mydoc.write(strHTML);

            mshtml.IHTMLElementCollection ec = (mshtml.IHTMLElementCollection)mydoc.all.tags("a");
            if (ec != null)
            {
                for (int i = 0; i < ec.length - 1; i++)
                {
                    mshtml.HTMLAnchorElementClass anchor;
                    anchor = (mshtml.HTMLAnchorElementClass)ec.item(i, 0);

                    if (!string.IsNullOrEmpty(anchor.name))
                    {
                        cmbAnchor.Items.Add(anchor.name);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public static String Search(string name)
        {
            buffer1 = new mshtml.HTMLDocument();
            buffer2 = (mshtml.IHTMLDocument2)buffer1;
            Console.WriteLine("Downloading search page for: {0}", name);
            string Data = Storage.wc.DownloadString($"https://vidstreaming.io/search.html?keyword={name}");

            buffer2.write(Data); // Write all the data to buffer1 so that we can enumerate it.
            mshtml.IHTMLElementCollection collection;
            Console.WriteLine("Searching for video-block");
            collection = buffer1.getElementsByTagName("li"); //Get all collections with the <li> tag.
            foreach (mshtml.IHTMLElement obj in collection)
            {
                if (obj.className == "video-block " || obj.className == "video-block click-hover") //if the element has a classname of "video-block " then we are dealing with a show.
                {
                    Console.WriteLine("Found video-block!");
                    node = obj; // set node to object.
                    break;      // escape the foreach loop.
                }
            }
            Expressions.vidStreamRegex = new Regex(Expressions.searchVideoRegex); // Don't say anything about parsing html with REGEX. This is a better than importing another library for this case.
            if (node == null)
            {
                return("E");
            }
            Match m = Expressions.vidStreamRegex.Match(node.innerHTML);

            return(m.Groups.Count >= 1 ? "https://vidstreaming.io" + m.Groups[1].Value : "E");
        }
Exemplo n.º 13
0
        static public IHTMLElement GetFrame(mshtml.IHTMLDocument2 doc)
        {
            IHTMLElement frame = null;

            mshtml.IHTMLWindow2 window2 = null;
            try
            {
                window2 = doc.parentWindow as mshtml.IHTMLWindow2;
                if (window2 != null)
                {
                    return(((mshtml.HTMLWindow2)window2).frameElement as IHTMLElement);
                }
            }
            catch (UnauthorizedAccessException) {
                //主页面和IFRAME页面处于不同域名的时候会报UnauthorizedAccessException,下面通过IHTMLWindow2->IWebBrowser2
                //比较IWebBrowser2和iframe元素url定位iframe
                SHDocVw.IWebBrowser2          browser          = CrossFrameIE.GetIWebBrowser2(window2);
                mshtml.IHTMLDocument3         parentDoc        = browser.Parent as mshtml.IHTMLDocument3;
                mshtml.IHTMLElementCollection framesCollection = parentDoc.getElementsByTagName("iframe") as mshtml.IHTMLElementCollection;
                foreach (mshtml.IHTMLElement f in framesCollection)
                {
                    SHDocVw.IWebBrowser2 wb2 = (SHDocVw.IWebBrowser2)((mshtml.HTMLFrameElement)f);
                    if (wb2.LocationURL == browser.LocationURL)
                    {
                        frame = f as IHTMLElement;
                        break;
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(frame);
        }
Exemplo n.º 14
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            mshtml.IHTMLDocument2 doc = webBrowser1.Document as mshtml.IHTMLDocument2;
            doc.execCommand("Print", true, 0);
            doc.close();

            ViewModel.SetPrintControlsVisibility(false);
        }
Exemplo n.º 15
0
        private void collecttheurl()
        {
            bool foundTheURL = false;

            mshtml.IHTMLDocument2 htmlDoc = webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2;

            List <mshtml.IHTMLDivElement> allDiv = htmlDoc.all.OfType <mshtml.IHTMLDivElement>().ToList();

            foreach (IHTMLElement div in allDiv)
            {
                //write2log(curElement.outerHTML);
                //write2log(curElement.tostring());
                //write2log(curElement.className);
                if (div.className == "rc")
                {
                    write2log("found a rc div");
                    IHTMLDOMNode divNode = (IHTMLDOMNode)div;
                    //write2log(div.innerHTML);
                    //write2log(div.className);

                    //var child = ((IHTMLDOMNode)divnode).firstChild;

                    if (!divNode.hasChildNodes())
                    {
                        continue;
                    }

                    IHTMLDOMChildrenCollection children = (IHTMLDOMChildrenCollection)divNode.childNodes;
                    foreach (IHTMLDOMNode child in children)
                    {
                        //write2log(child.GetType().Name);
                        if (child != null && child.GetType().Name == "HTMLHeaderElementClass")
                        {
                            if (child.hasChildNodes())
                            {
                                IHTMLAnchorElement ancharchild = (IHTMLAnchorElement)child.firstChild;
                                //write2log(ancharchild.GetType().Name);
                                if (ancharchild != null && ancharchild.GetType().Name == "HTMLAnchorElementClass")
                                {
                                    write2urlList(GoogleQueryConf.queryterms[GoogleQueryConf.queryIndex] + "\t => \t" + ancharchild.href);
                                    write2urlList(ancharchild.href);
                                    foundTheURL = true;
                                    break;
                                }
                            }
                        }
                        //write2log(child.ToString());
                    }
                }

                if (foundTheURL)
                {
                    break;
                }
            }
            return;
        }
Exemplo n.º 16
0
        public static String extractDownloadUri(string episodeUri)
        {
            Console.WriteLine("Extracting Download URL for {0}", episodeUri);
            WebClient wc   = new WebClient();
            string    Data = wc.DownloadString(episodeUri);

            buffer3 = new mshtml.HTMLDocument();
            wc.Dispose();
            buffer3.designMode = "off";
            buffer4            = (mshtml.IHTMLDocument2)buffer3;
            buffer4.write(Data); // beware the hang.
            Expressions.vidStreamRegex = new Regex(Expressions.videoIDRegex);
            IHTMLElementCollection col = buffer3.getElementsByTagName("IFRAME");
            Match  match;
            string id = null;

            foreach (IHTMLElement elem in col)
            {
                match = Expressions.vidStreamRegex.Match(elem.getAttribute("src"));
                if (match.Success)
                {
                    id = match.Groups[0].Value;
                    break;
                }
                else
                {
                    return(null);
                }
            }
            col = null;
            buffer3.clear();
            buffer4.clear();

            Task <String> response = Storage.client.GetStringAsync($"https://vidstreaming.io/ajax.php?id={id}");

            Expressions.vidStreamRegex = new Regex(Expressions.downloadLinkRegex);
            match = Expressions.vidStreamRegex.Match(response.Result);
            if (match.Success)
            {
                string ursTruly = match.Groups[0].Value.Replace("\\", string.Empty);
                int    ids      = Extensions.indexOfEquals(ursTruly) + 1;
                if (ursTruly.Contains("goto.php"))
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ursTruly);
                    request.AutomaticDecompression = DecompressionMethods.GZip;
                    WebResponse res = request.GetResponse();
                    string      s   = res.ResponseUri.ToString();
                    return(s);
                }
                else
                {
                    return(ursTruly);
                }
            }
            return(null);
        }
Exemplo n.º 17
0
 /// <summary>
 /// 获取元素容器iframe, 如果不存在返回null
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 static public IHTMLElement GetFrame(IHTMLElement element)
 {
     if (element == null)
     {
         return(null);
     }
     mshtml.IHTMLDocument2 doc = null;
     doc = element.document as mshtml.IHTMLDocument2;
     return(GetFrame(doc));
 }
Exemplo n.º 18
0
        public static bool ScrollToAbsolutePoint(IntPtr hwnd, mshtml.IHTMLDocument2 doc, int scrollTop, int y, int scrollHeight, int winHeight, ref Point fakeMousePoint, bool scrollFast, bool isTimeout, HtmlElement htmlElement)
        {
            int    num2;
            bool   flag   = false;
            int    num    = 0;
            Random random = new Random();

            if (isTimeout)
            {
                if (htmlElement == null)
                {
                    return(flag);
                }
                int num3 = y - (winHeight / 2);
                if (num3 < 0)
                {
                    num3 = 0;
                }
                else if (num3 > (scrollHeight - winHeight))
                {
                    num3 = scrollHeight - winHeight;
                }
                htmlElement.ScrollTop = num3;
                return(true);
            }
            if (scrollFast)
            {
                num2 = 100;
            }
            else
            {
                num2 = random.Next(5, 10);
            }
            CheckMousePoint(hwnd, ref fakeMousePoint, doc);
            while (!flag && (num < num2))
            {
                int windowMessageLParam = GetWindowMessageLParam(hwnd, fakeMousePoint);
                if ((y <= ((scrollTop + (winHeight / 2)) - 120)) && (scrollTop > 0))
                {
                    scrollTop = ((scrollTop - 120) >= 0) ? (scrollTop - 120) : 0;
                    WindowUtil.PostMessage(hwnd, 0x20a, 0x780000, windowMessageLParam);
                }
                else if ((y >= ((scrollTop + (winHeight / 2)) + 120)) && ((scrollTop + winHeight) < scrollHeight))
                {
                    scrollTop = (((scrollTop + winHeight) + 120) <= scrollHeight) ? (scrollTop + 120) : (scrollHeight - winHeight);
                    WindowUtil.PostMessage(hwnd, 0x20a, -7864320, windowMessageLParam);
                }
                else
                {
                    flag = true;
                }
                num++;
            }
            return(flag);
        }
Exemplo n.º 19
0
 private string GetHtmlDocText(mshtml.IHTMLDocument2 htmlDoc, bool html)
 {
     if (html)
     {
         return(htmlDoc.body.parentElement.outerHTML);
     }
     else
     {
         return(htmlDoc.body.innerText);
     }
 }
Exemplo n.º 20
0
        public static bool MoveToDest(IntPtr hwnd, HtmlElement htmlElement, mshtml.IHTMLDocument2 doc, int x, int y, ref Point fakeMousePoint, bool scrollfast, bool isTimeout)
        {
            bool flag         = true;
            int  clientWidth  = 0;
            int  clientHeight = 0;
            int  scrollWidth  = 0;
            int  scrollHeight = 0;

            if ((GetWindowWidthAndHeight(hwnd, doc, ref clientWidth, ref clientHeight, ref scrollWidth, ref scrollHeight) != null) && (htmlElement != null))
            {
                int scrollLeft = htmlElement.ScrollLeft;
                int scrollTop  = htmlElement.ScrollTop;
                if ((clientWidth == 0) && (clientHeight == 0))
                {
                    return(flag);
                }
                flag = ScrollToAbsolutePoint(hwnd, doc, scrollTop, y + scrollTop, scrollHeight, clientHeight, ref fakeMousePoint, scrollfast, isTimeout, htmlElement);
                if (!flag)
                {
                    return(flag);
                }
                flag = false;
                int num7 = 0;
                if (((scrollLeft + x) + (clientWidth / 2)) > scrollWidth)
                {
                    num7 = scrollWidth - clientWidth;
                }
                else if ((scrollLeft + x) < (clientWidth / 2))
                {
                    num7 = 0;
                }
                else
                {
                    num7 = (scrollLeft + x) - (clientWidth / 2);
                }
                htmlElement.ScrollLeft = num7;
                if ((x + scrollLeft) < 0)
                {
                    x = 4;
                }
                else if ((x + scrollLeft) > scrollWidth)
                {
                    x = clientWidth - 8;
                }
                if (((scrollLeft + x) >= num7) && ((scrollLeft + x) <= (num7 + clientWidth)))
                {
                    SetMousePoint(hwnd, ref fakeMousePoint, x, y, doc);
                    int lParam = (fakeMousePoint.Y << 0x10) + fakeMousePoint.X;
                    WindowUtil.PostMessage(hwnd, 0x200, 0, lParam);
                    flag = true;
                }
            }
            return(flag);
        }
Exemplo n.º 21
0
        private static bool GetEleParentFrames(mshtml.IHTMLDOMNode root, mshtml.IHTMLDOMNode node, List <mshtml.IHTMLDOMNode> frames)
        {
            bool flag = false;

            if (root == node)
            {
                return(true);
            }
            bool flag2 = false;

            switch (root.nodeName.ToLower())
            {
            case "frame":
            case "iframe":
                flag2 = true;
                break;
            }
            IHTMLDOMChildrenCollection childNodes = null;

            if (flag2)
            {
                SHDocVw.IWebBrowser2 browser = root as SHDocVw.IWebBrowser2;
                if (browser != null)
                {
                    mshtml.IHTMLDocument2 document = browser.Document as mshtml.IHTMLDocument2;
                    if (document != null)
                    {
                        mshtml.IHTMLDOMNode parentElement = document.body.parentElement as mshtml.IHTMLDOMNode;
                        childNodes = parentElement.childNodes as IHTMLDOMChildrenCollection;
                    }
                }
            }
            if (childNodes == null)
            {
                childNodes = root.childNodes as IHTMLDOMChildrenCollection;
            }
            if (childNodes == null)
            {
                return(false);
            }
            for (int i = 0; i < childNodes.length; i++)
            {
                mshtml.IHTMLDOMNode node3 = childNodes.item(i) as mshtml.IHTMLDOMNode;
                if (GetEleParentFrames(node3, node, frames))
                {
                    if (flag2)
                    {
                        frames.Add(root);
                    }
                    flag = true;
                }
            }
            return(flag);
        }
        private void web_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {
            mshtml.IHTMLDocument2 htmlDocument = automation_browser.Document.DomDocument as mshtml.IHTMLDocument2;
            htmlDocument2 = htmlDocument;



            this.document            = this.automation_browser.Document;
            this.document.MouseDown += new System.Windows.Forms.HtmlElementEventHandler(document_MouseDown);
            //this.document.MouseOver += new System.Windows.Forms.HtmlElementEventHandler(document_MouseOver);
            //this.document.MouseLeave += new System.Windows.Forms.HtmlElementEventHandler(document_MouseLeave);
        }
Exemplo n.º 23
0
        private void File_Print(object sender, RoutedEventArgs e)
        {
            string printContents;

            printContents = ViewModel.GetPrintContents();

            mshtml.IHTMLDocument2 doc = webBrowser1.Document as mshtml.IHTMLDocument2;
            doc.clear();
            doc.write(printContents);
            doc.execCommand("Print", true, 0);
            doc.close();
        }
Exemplo n.º 24
0
        public static mshtml.IHTMLDocument2 GetIEWindowDocument(IntPtr hwnd)
        {
            object ppvObject = new object();
            int    lParam    = 0;
            Guid   riid      = new Guid();
            int    wMsg      = WindowUtil.RegisterWindowMessage("WM_Html_GETOBJECT");

            WindowUtil.ObjectFromLresult(WindowUtil.SendMessage(hwnd, wMsg, 0, lParam), ref riid, 0, ref ppvObject);
            mshtml.IHTMLDocument2 document = (mshtml.IHTMLDocument2)ppvObject;
            ppvObject = null;
            return(document);
        }
Exemplo n.º 25
0
        // Returns null in case of failure.
        public static IHTMLDocument2 GetDocumentFromWindow(IHTMLWindow2 htmlWindow)
        {
            if (htmlWindow == null)
            {
                return(null);
            }

            // First try the usual way to get the document.
            try
            {
                IHTMLDocument2 doc = htmlWindow.document;
                return(doc);
            }
            catch (COMException comEx)
            {
                // I think COMException won't be ever fired but just to be sure ...
                if (comEx.ErrorCode != E_ACCESSDENIED)
                {
                    return(null);
                }
            }
            catch (System.UnauthorizedAccessException)
            {
            }
            catch
            {
                // Any other error.
                return(null);
            }

            // At this point the error was E_ACCESSDENIED because the frame contains a document from another domain.
            // IE tries to prevent a cross frame scripting security issue.
            try
            {
                // Convert IHTMLWindow2 to IWebBrowser2 using IServiceProvider.
                IServiceProvider sp = (IServiceProvider)htmlWindow;

                // Use IServiceProvider.QueryService to get IWebBrowser2 object.
                Object brws = null;
                sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out brws);

                // Get the document from IWebBrowser2.
                SHDocVw.IWebBrowser2 browser = (SHDocVw.IWebBrowser2)(brws);

                mshtml.IHTMLDocument2 doc = browser.Document as mshtml.IHTMLDocument2;
                return((IHTMLDocument2)doc);
            }
            catch
            {
            }

            return(null);
        }
Exemplo n.º 26
0
        public static bool GetRadioRect(mshtml.IHTMLDocument2 doc, ref Rectangle rect, string itemName, string tagStr, string indexStr)
        {
            bool flag = false;

            mshtml.IHTMLElement elem = GetRadioElement(doc, itemName, tagStr, indexStr);
            if (elem != null)
            {
                rect = GetElementRect(doc.body, elem);
                flag = true;
            }
            return(flag);
        }
Exemplo n.º 27
0
 //private void wb_NavigateComplete2(object pdisp, ref object url)
 //{
 //    mshtml.IHTMLDocument2 doc = (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).Document as mshtml.IHTMLDocument2;
 //    doc.parentWindow.execScript("function alert(str){return ''}", "javascript");
 //}
 private void wb_NavigateComplete2(object pdisp, ref object url)
 {
     try
     {
         doc = wb.Document as mshtml.IHTMLDocument2;
         //执行javascript脚本,覆盖系统的confirm函数,直接return true,这样调用confirm函数都会执行到确认按钮了,同理可以重写系统中的其他函数
         doc.parentWindow.execScript("function confirm(){return true;}", "javascript");
         doc.parentWindow.execScript("function alert(){}", "javascript");//设置为alert为空函数体,就不会挂起javascript代码执行了
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 28
0
        private void File_PrintPreview(object sender, RoutedEventArgs e)
        {
            string printContents;

            printContents = ViewModel.GetPrintContents();

            mshtml.IHTMLDocument2 doc = webBrowser1.Document as mshtml.IHTMLDocument2;
            doc.clear();
            doc.write(printContents);
            doc.close();

            ViewModel.SetPrintControlsVisibility(true);
        }
Exemplo n.º 29
0
        public static bool MoveToDest(IntPtr hwnd, mshtml.IHTMLDocument2 doc, Point to, ref Point fakeMousePoint)
        {
            bool flag         = false;
            int  clientWidth  = 0;
            int  clientHeight = 0;
            int  scrollWidth  = 0;
            int  scrollHeight = 0;

            if ((GetWindowWidthAndHeight(hwnd, doc, ref clientWidth, ref clientHeight, ref scrollWidth, ref scrollHeight) != null) && ((clientWidth != 0) || (clientHeight != 0)))
            {
                int num5 = 50;
                if ((Math.Abs((int)(fakeMousePoint.Y - to.Y)) >= num5) || (Math.Abs((int)(fakeMousePoint.X - to.X)) >= num5))
                {
                    if (((to.X >= 0) && (to.X < clientWidth)) && ((to.Y >= 0) && (to.Y <= clientHeight)))
                    {
                        Random random = new Random();
                        int    num6   = 0;
                        int    num7   = 0;
                        if ((fakeMousePoint.X - to.X) > 0)
                        {
                            num6 = -random.Next(Math.Max(fakeMousePoint.X - to.X, 50));
                        }
                        else if ((fakeMousePoint.X - to.X) < 0)
                        {
                            num6 = random.Next(Math.Max(to.X - fakeMousePoint.X, 50));
                        }
                        if ((fakeMousePoint.Y - to.Y) > 0)
                        {
                            num7 = -random.Next(Math.Max(fakeMousePoint.Y - to.Y, 50));
                        }
                        else if ((fakeMousePoint.Y - to.Y) < 0)
                        {
                            num7 = random.Next(Math.Max(to.Y - fakeMousePoint.Y, 50));
                        }
                        SetMousePoint(ref fakeMousePoint, fakeMousePoint.X + num6, fakeMousePoint.Y + num7, clientWidth, clientHeight);
                        int lParam = (fakeMousePoint.Y << 0x10) + fakeMousePoint.X;
                        WindowUtil.PostMessage(hwnd, 0x200, 0, lParam);
                    }
                    return(flag);
                }
                flag = true;
                if ((fakeMousePoint.Y != to.Y) || (fakeMousePoint.X != to.X))
                {
                    SetMousePoint(ref fakeMousePoint, to.X, to.Y, clientWidth, clientHeight);
                    int num9 = (fakeMousePoint.Y << 0x10) + fakeMousePoint.X;
                    WindowUtil.PostMessage(hwnd, 0x200, 0, num9);
                }
            }
            return(flag);
        }
Exemplo n.º 30
0
        public static bool GetButtonRect(mshtml.IHTMLDocument2 doc, ref Rectangle rect, string itemName, string tagStr, string indexStr)
        {
            mshtml.IHTMLElement elem = GetButtonElement(doc, itemName, tagStr, indexStr);
            bool flag = false;

            if (elem != null)
            {
                rect = GetElementRect(doc.body, elem);
                flag = true;
            }
            if (elem != null)
            {
                Marshal.ReleaseComObject(elem);
            }
            return(flag);
        }
Exemplo n.º 31
0
        void b_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            doc = (IHTMLDocument2)b.Document.DomDocument;

            string result = "<html>";

            IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)doc.all.tags("head")).item(null, 0);

            result += "<head>" + head.innerHTML + "</head>";

            if (null != doc)
            {
                foreach (IHTMLElement element in doc.all)
                {
                    if (element is mshtml.IHTMLDivElement)
                    {
                        dynamic div = element as HTMLDivElement;

                        if (FindByID)
                        {
                            string id = div.id;

                            if (id == Element)
                            {
                                result += "<body>" + div.IHTMLElement_innerHTML + "</body></html>";

                                break;
                            }
                        }
                        else
                        {
                            string className = div.className;

                            if (className == Element)
                            {
                                result += "<body>" + div.IHTMLElement_innerHTML + "</body></html>";

                                break;
                            }
                        }
                    }
                }
            }
            doc.close();

            this.Add(result);
        }
Exemplo n.º 32
0
        private void browser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            try
            {
                SHDocVw.IWebBrowser2 doc=e.pDisp as SHDocVw.IWebBrowser2;

                if (doc==(sender as AxSHDocVw.AxWebBrowser).GetOcx())
                {

                    try
                    {

                        HTMLDocument = (IHTMLDocument2) this.browserControl.Document;
                        this.myDocument = (mshtml.HTMLDocument)HTMLDocument;
                        //this.window2 = (mshtml.IHTMLWindow2)HTMLDocument.parentWindow;

                        //this.window2.onscroll=new mshtml.HTMLWindowEvents2_onscrollEventHandler
                        //mshtml.HTMLWindowEvents2_onscrollEventHandler(this.HTMLWindow_onscroll);

                        //					//this.htmlViewerEvent2 -= new htmlViewerEventHandler2(mouseEvent2);
                        //					this.htmlViewerEvent2 += new htmlViewerEventHandler2(mouseEvent2);
                        //					//this.htmlViewerEvent -= new htmlViewerEventHandler(mouseEvent);//kill the extra event handlers
                        //					this.htmlViewerEvent += new htmlViewerEventHandler(mouseEvent);
                        //
                        //					this.HTMLDocument.body.onmouseup = this;
                        //					this.HTMLDocument.body.onclick = this;
                        //					this.HTMLDocument.body.onselectstart = this;
                        //					this.HTMLDocument.body.onmousedown = this;
                        //					this.HTMLDocument.body.onmousemove = this;
                        //					this.HTMLDocument.body.ondragstart = this;
                        //					this.HTMLDocument.body.onmouseout = this;
                        //					this.myDocument.oncontextmenu = this;
                        //					this.window2.onscroll = this;//
                        ////					IHTMLDocument2 HTMLDoc1 =	(IHTMLDocument2)this.browserControl.Document;
                        ////					IHTMLWindow2 HTMLWin1 = (mshtml.IHTMLWindow2)HTMLDocument.parentWindow;
                        ////					this.HTMLWindow.onscroll = new mshtml.HTMLWindowEvents2_onscrollEventHandler(this.HTMLWindow_onscroll);
                        //						//mshtml.HTMLWindowEvents2_onscrollEventHandler(this.HTMLWindow_onscroll);
                        //					//HTMLWindow.o
                        //Trace.WriteLine("Page is completed");
                    }
                    catch(Exception ex)
                    {
                        WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Module ::: WebSharing  private void browser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)",ex,"",false);
                    }
                }
            }
            catch(Exception ex)
            {
                WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Module ::: WebSharing  private void browser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)",ex,"",false);
            }
        }
Exemplo n.º 33
0
 internal HtmlDocument(System.Windows.Forms.HtmlDocument htmlDocument)
 {
     sysWinFormHtmlDoc = htmlDocument;
     msHtmlDocInterface = (mshtml.IHTMLDocument2)htmlDocument.DomDocument;
 }
Exemplo n.º 34
0
 public void DefaultMethod()
 {
     try
     {
         HTMLDocument = (IHTMLDocument2) this.browserControl.Document;
         HTMLWindow2 win = (HTMLWindow2)this.HTMLDocument.parentWindow;
     }
     catch(Exception ex)
     {
         WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Module ::: WebSharing  public void DefaultMethod()",ex,"",false);
     }
     //Trace.WriteLine("Object: " + [email protected] + ", Type: " + [email protected]);
 }
        private void ViewHTML(string text)
        {
            try
            {
                mshtml.IHTMLDocument2 document = (mshtml.IHTMLDocument2)webBrowser.Document;
                //mshtml.IHTMLDocument2 document = (mshtml.IHTMLDocument2)htmlEditor.Document;
                //htmlEditor.LoadDocument(text);
                document.write("");
                document.close();
                document.write(new object[] {text});
            //
            //				mshtml.IHTMLElementCollection coll = (IHTMLElementCollection)document.all.tags("table");
            //				foreach ( IHTMLElement el in coll )
            //				{
            //					if ( el is mshtml.IHTMLTable )
            //					{
            //						((mshtml.IHTMLTable)el).border = 1;
            //					}
            //				}
                if ( document != null )
                {
                    htmlDocument = document;
                    mshtml.HTMLDocumentEvents2_Event iEvent
                        = (mshtml.HTMLDocumentEvents2_Event)htmlDocument;
                    iEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler(iEvent_onclick);

                    // On Error Event
                    mshtml.HTMLWindowEvents2_Event windowEvents
                        = (mshtml.HTMLWindowEvents2_Event)htmlDocument.parentWindow;
                    windowEvents.onerror += new HTMLWindowEvents2_onerrorEventHandler(windowEvents_onerror);
                }
            }
            catch
            {
                // Ignore
            }
        }