Example #1
0
        private static void OnDocCompleted(int procId, IHTMLDocument2 doc)
        {
            Console.WriteLine(procId.ToString() + ") OnDocCompleted called [Doc:" + doc.ToString() + "]");

            //on document completion add our custom DIV
            //create sample element
            IHTMLElement elem = doc.createElement("div");

            elem.innerHTML = "Hello from RemoteCOM";
            elem.setAttribute("id", "RemoteCOM_SampleDiv", 0);
            //style it
            IHTMLStyle2 style2 = elem.style as IHTMLStyle2;

            style2.right          = 0;
            elem.style.top        = 0;
            style2.position       = "absolute";
            elem.style.border     = "2px solid #FFFF00";
            elem.style.background = "#FFFFC0";
            elem.style.zIndex     = 10000;
            elem.style.font       = "bold 12px Helvetica";
            elem.style.padding    = "5px";
            //insert new element into body
            IHTMLDOMNode bodyNode = doc.body as IHTMLDOMNode;
            IHTMLDOMNode elemNode = elem as IHTMLDOMNode;

            bodyNode.appendChild(elemNode);
            //remember to force release com objects
            Marshal.ReleaseComObject(elem);
            Marshal.ReleaseComObject(style2);
            Marshal.ReleaseComObject(elemNode);
            Marshal.ReleaseComObject(bodyNode);
            return;
        }
Example #2
0
        private void OnDocumentComplete(object pDisp, ref object Url)
        {
            IHTMLDocument2 document = (IHTMLDocument2)webBrowser.Document;
            IHTMLElement   ele      = document.createElement("button");

            ele.innerText = "Show Dialog";
            (document.body as IHTMLDOMNode).appendChild(ele as IHTMLDOMNode);
            ((HTMLButtonElementEvents2_Event)ele).onclick
                += new HTMLButtonElementEvents2_onclickEventHandler(Button_onclick);
        }
Example #3
0
		/// <summary>
		/// This embeds an inline css stylesheet that allows tags
		/// in the users guide html that are in the class "hideonline"
		/// to be hidden in the version poseted to the website
		/// </summary>
		/// <param name="htmlDoc"></param>
		private static void AddEmbeddedCSS( IHTMLDocument2 htmlDoc )
		{
			IHTMLStyleElement style = htmlDoc.createElement( "style" ) as IHTMLStyleElement;
			style.type = "text/css";
			style.styleSheet.cssText = ".hideonline{ display:none; }";

			IHTMLElementCollection collection = htmlDoc.all.tags( "head" ) as IHTMLElementCollection;
			Debug.Assert( collection != null );
			Debug.Assert( collection.length == 1 );

			mshtml.IHTMLDOMNode head = collection.item( 0, 0 ) as IHTMLDOMNode;
			Debug.Assert( head != null );
			head.appendChild( style as IHTMLDOMNode );
		}
Example #4
0
        private BlogPostRegions ParseBlogPostIntoTemplate(Stream stream, string postSourceUrl, IProgressHost progress)
        {
            progress.UpdateProgress(Res.Get(StringId.ProgressCreatingEditingTemplate));

            //parse the document to create the blog template
            IHTMLDocument2 doc2 = HTMLDocumentHelper.GetHTMLDocumentFromStream(stream, postSourceUrl);
            IHTMLDocument3 doc  = (IHTMLDocument3)doc2;

            IHTMLElement[] titleElements = HTMLDocumentHelper.FindElementsContainingText(doc2, TEMPORARY_POST_TITLE_GUID);

            IHTMLElement bodyElement = HTMLDocumentHelper.FindElementContainingText(doc2, TEMPORARY_POST_BODY_GUID);

            if (bodyElement != null && bodyElement.tagName == "P")
            {
                //the body element is the <p> we planted, so replace it with a DIV since that will be the safest
                //element to have a as parent to all post content.
                IHTMLElement div = doc2.createElement("div");
                (bodyElement.parentElement as IHTMLDOMNode).replaceChild(div as IHTMLDOMNode, bodyElement as IHTMLDOMNode);
                bodyElement = div;
            }

            //locate the title element.  Note that is there are more than 1 copies of the title text detected, we use the one
            //that is anchored closest to the left or the body element.
            if (titleElements.Length > 0)
            {
                BlogPostRegions regions = new BlogPostRegions();
                regions.Document     = (IHTMLDocument)doc;
                regions.TitleRegions = titleElements;
                regions.BodyRegion   = bodyElement;

                progress.UpdateProgress(100, 100);
                return(regions);
            }
            else
            {
                throw new Exception("unable to access test post.");
            }
        }
Example #5
0
        /// <summary>
        /// Creates and appends an HTMLElement to the end of the document DOM
        /// </summary>
        /// <param name="TagName">a, img, table,...</param>
        public IHTMLDOMNode AppendChild(string TagName)
        {
            if (m_pDoc2 == null)
            {
                return(null);
            }
            IHTMLElement elem = m_pDoc2.createElement(TagName) as IHTMLElement;

            if (elem == null)
            {
                return(null);
            }
            //Append to body DOM collection
            IHTMLDOMNode nd   = (IHTMLDOMNode)elem;
            IHTMLDOMNode body = (IHTMLDOMNode)m_pDoc2.body;

            return(body.appendChild(nd));
        }
Example #6
0
        /*************************************************************************************************************/
        /// <summary>
        /// 时间:2016年9月14日12:41:56
        /// 传入找到的DOC文档
        /// </summary>
        /// <param name="IHTMLDocument2 Document2,string url_remote_js(文件名)" ></param>
        public void add_doc_element_test(IHTMLDocument2 Document2, string url)
        {
            this.methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;//程序执行位置代码块的方法名
            this.msg        = methodName + "进入此方法!";
            this.log_to(Debug_config, methodName, this.msg);

            try
            {
                IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)Document2.all.tags("head")).item(null, 0);
                var          body = (HTMLBody)Document2.body;



                /**************************************************添加Javascript脚本******************************************/

                this.msg = methodName + "成功》加载JS:\n" + url;
                this.log_to(Debug_config, methodName, this.msg);

                IHTMLElement scriptElement = Document2.createElement("script");
                scriptElement.setAttribute("type", "text/javascript");
                scriptElement.setAttribute("src", url);
                body.insertAdjacentElement("afterBegin", scriptElement);

                // ((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptElement);
                /**************************************************添加Javascript脚本******************************************/

                //string btnString = @"<input type='button' value='[email protected] C#' onclick='FindPassword()' />";
                //body.insertAdjacentHTML("afterBegin", btnString);
            }
            catch (Exception e)
            {
                //System.Windows.Forms.MessageBox.Show(e.ToString());
                this.msg = methodName + e.ToString();
                this.log_to(Debug_config, methodName, this.msg);
            }
        }
Example #7
0
        private static void OnDocCompleted(int procId, IHTMLDocument2 doc)
        {
            Console.WriteLine(procId.ToString() + ") OnDocCompleted called [Doc:" + doc.ToString() + "]");

            //on document completion add our custom DIV
            //create sample element
            IHTMLElement elem = doc.createElement("div");
            elem.innerHTML = "Hello from RemoteCOM";
            elem.setAttribute("id", "RemoteCOM_SampleDiv", 0);
            //style it
            IHTMLStyle2 style2 = elem.style as IHTMLStyle2;
            style2.right = 0;
            elem.style.top = 0;
            style2.position = "absolute";
            elem.style.border = "2px solid #FFFF00";
            elem.style.background = "#FFFFC0";
            elem.style.zIndex = 10000;
            elem.style.font = "bold 12px Helvetica";
            elem.style.padding = "5px";
            //insert new element into body
            IHTMLDOMNode bodyNode = doc.body as IHTMLDOMNode;
            IHTMLDOMNode elemNode = elem as IHTMLDOMNode;
            bodyNode.appendChild(elemNode);
            //remember to force release com objects
            Marshal.ReleaseComObject(elem);
            Marshal.ReleaseComObject(style2);
            Marshal.ReleaseComObject(elemNode);
            Marshal.ReleaseComObject(bodyNode);
            return;
        }
 /// <summary>
 /// Add a new element of the specified type to the specified container
 /// </summary>
 /// <param name="elementName"></param>
 /// <param name="htmlDocument"></param>
 /// <param name="container"></param>
 /// <returns></returns>
 static public IHTMLElement AddNewElementToContainer(string elementName, IHTMLDocument2 htmlDocument, IHTMLElement container)
 {
     IHTMLElement newElement = htmlDocument.createElement(elementName);
     ((IHTMLDOMNode)container).appendChild((IHTMLDOMNode)newElement);
     return newElement;
 }
Example #9
0
 public IHTMLElement createElement(string eTag)
 {
     return(_innerDoc2.createElement(eTag));
 }