ActiveX (4) Introduction to important interfaces of mshtml namespaces, activexmshtml

Source: Internet
Author: User

ActiveX (4) Introduction to important interfaces of mshtml namespaces, activexmshtml

In the previous article, ActiveX (3) ActiveX called Js, we can obtain the strong window object interface in js, that is, mshtml. IHTMLWindow2. Through this interface, we can call js functions. Let's try other methods to see if the results meet expectations:

  

        private void btnAlert_Click(object sender, EventArgs e)        {            if (this.window2 != null)            {                this.window2.alert("C#CodeAlert:" + this.txtPwd.Text);            }        }        private void btnLocation_Click(object sender, EventArgs e)        {            if (this.window2 != null && this.window2.location != null)            {                this.window2.alert(this.window2.location.toString());            }        }

  

Haha, try it. No problem. However, it is found that the location attribute is read-only. If the location attribute is forcibly set through reflection, an exception is thrown.

Now that we know the window, what about the document? Does the mshtml namespace provide corresponding interfaces? After discovery, document implements the following two interfaces:

  

[Guid ("identifier")] [TypeLibType (4160)] public interface IHTMLDocument2: IHTMLDocument {[DispId (1005)] IHTMLElement activeElement {get;} [DispId (1022)] dynamic alinkColor {get; set;} [DispId (1003)] IHTMLElementCollection all {get;} [DispId (1007)] IHTMLElementCollection anchors {get;} [DispId (1008)] IHTMLElementCollection applets {get;} [DispId (-501)] dynamic bgColor {get; set;} [DispId (1004)] IHTMLElement body {get;} [DispId (1032)] string charset {get; set;} [DispId (1030)] string cookie {get; set;} [DispId (1033)] string defaultCharset {get; set ;} [DispId (1014)] string designMode {get; set;} [DispId (1029)] string domain {get; set;} [DispId (1015)] IHTMLElementCollection embeds {get ;} [DispId (1031)] bool expando {get; set;} [DispId (-2147413110)] dynamic fgColor {get; set;} [DispId (1043)] string fileCreatedDate {get;} [DispId (1044)] string fileModifiedDate {get;} [DispId (1042)] string fileSize {get;} [DispId (1045)] string fileUpdatedDate {get;} [DispId (1010)] IHTMLElementCollection forms {get;} [DispId (1019)] FramesCollection frames {get;} [DispId (1011)] IHTMLElementCollection images {get;} [DispId (1028)] string lastModified {get;} [DispId (1024)] dynamic linkColor {get; set;} [DispId (1009)] IHTMLElementCollection links {get;} [DispId (1026)] HTMLLocation {get;} [DispId (1041)] string mimeType {get;} [DispId (1048)] string nameProp {get;} [DispId (-2147412090)] dynamic onafterupdate {get; set;} [DispId (-2147412091)] dynamic onbeforeupdate {get; set ;} [DispId (-2147412104)] dynamic onclick {get; set;} [DispId (-2147412103)] dynamic ondblclick {get; set;} [DispId (-2147412077)] dynamic ondragstart {get; set;} [DispId (-2147412074)] dynamic onerrorupdate {get; set;} [DispId (-2147412099)] dynamic onhelp {get; set ;} [DispId (-2147412107)] dynamic onkeydown {get; set;} [DispId (-2147412105)] dynamic onkeypress {get; set;} [DispId (-2147412106)] dynamic onkeyup {get; set;} [DispId (-2147412110)] dynamic onmousedown {get; set;} [DispId (-2147412108)] dynamic onmousemove {get; set ;} [DispId (-2147412111)] dynamic onmouseout {get; set;} [DispId (-2147412112)] dynamic onmouseover {get; set;} [DispId (-2147412109)] dynamic onmouseup {get; set;} [DispId (-2147412087)] dynamic onreadystatechange {get; set;} [DispId (-2147412093)] dynamic onrowenter {get; set ;} [DispId (-2147412094)] dynamic onrowexit {get; set;} [DispId (-2147412075)] dynamic onselectstart {get; set;} [DispId (1034)] IHTMLWindow2 parentWindow {get;} [DispId (1021)] IHTMLElementCollection plugins {get;} [DispId (1047)] string protocol {get;} [DispId (1018)] string readyState {get;} [DispId (1027)] string referrer {get;} [DispId (1001)] dynamic Script {get;} [DispId (1013)] IHTMLElementCollection scripts {get;} [DispId (1046)] string security {get;} [DispId (1017)] IHTMLSelectionObject selection {get;} [DispId (1069)] HTMLStyleSheetsCollection styleSheets {get;} [DispId (1012)] string title {get; set;} [DispId (1025)] string url {get; set;} [DispId (1023)] dynamic vlinkColor {get; set;} [DispId (1058)] void clear (); [DispId (1057)] void close (); [DispId (1067)] IHTMLElement createElement (string eTag); [DispId (1071)] IHTMLStyleSheet createStyleSheet (string bstrHref = "", int lIndex =-1); [DispId (1068)] IHTMLElement elementFromPoint (int x, int y); [DispId (1065)] bool execCommand (string Region ID, bool showUI = false, object value = Type. missing); [DispId (1066)] bool execCommandShowHelp (string prior ID); [DispId (1056)] dynamic open (string url = "text/html", object name = Type. missing, object features = Type. missing, object replace = Type. missing); [DispId (1060)] bool queryCommandEnabled (string Relative ID); [DispId (1062)] bool queryCommandIndeterm (string Relative ID); [DispId (1061)] bool queryCommandState (string prior ID); [DispId (1059)] bool queryCommandSupported (string prior ID); [DispId (1063)] string queryCommandText (string prior ID); [DispId (1064)] dynamic queryCommandValue (string prior ID); [DispId (1070)] string toString (); [DispId (1054)] void write (params object [] psarray); [DispId (1055)] void writeln (params object [] psarray );}IHTMLDocument2

 

[Guid ("3050F485-98B5-11CF-BB82-00AA00BDCE0B")] [TypeLibType (4160)] public interface IHTMLDocument3 {[DispId (1080)] string baseUrl {get; set;} [DispId (-2147417063)] dynamic childNodes {get;} [DispId (-2147412995)] string dir {get; set;} [DispId (1075)] IHTMLElement documentElement {get;} [DispId (1079)] bool enableDownload {get; set;} [DispId (1082)] bool inheritStyleSheets {get; set;} [DispId (-2147412043)] dynamic onbeforeeditfocus {get; set ;} [DispId (-2147412048)] dynamic oncellchange {get; set;} [DispId (-2147412047)] dynamic oncontextmenu {get; set;} [DispId (-2147412071)] dynamic ondataavailable {get; set;} [DispId (-2147412072)] dynamic ondatasetchanged {get; set;} [DispId (-2147412070)] dynamic ondatasetcomplete {get; set ;} [DispId (-2147412065)] dynamic onpropertychange {get; set;} [DispId (-2147412050)] dynamic onrowsdelete {get; set;} [DispId (-2147412049)] dynamic onrowsinserted {get; set;} [DispId (-2147412044)] dynamic onstop {get; set;} [DispId (1078)] IHTMLDocument2 parentDocument {get ;} [DispId (1077)] string uniqueID {get;} [DispId (-2147417605)] bool attachEvent (string @ event, object pdisp); [DispId (1076)] IHTMLDocument2 createDocumentFragment (); [DispId (1074)] IHTMLDOMNode createTextNode (string text); [DispId (-2147417604)] void detachEvent (string @ event, object pdisp ); [DispId (1088)] IHTMLElement getElementById (string v); [DispId (1086)] IHTMLElementCollection getElementsByName (string v); [DispId (1087)] IHTMLElementCollection getElementsByTagName (string v ); [DispId (1073)] void recalc (bool fForce = false); [DispId (1072)] void releaseCapture ();}IHTMLDocument3

Several important methods found in IHTMLDocument3 are not found in ihtmldocument2.

        [DispId(1088)]        IHTMLElement getElementById(string v);        [DispId(1086)]        IHTMLElementCollection getElementsByName(string v);        [DispId(1087)]        IHTMLElementCollection getElementsByTagName(string v);

 

What about element? There seems to be a lot of elements, and there are four in total. There are two commonly used elements: IHTMLElement and IHTMLElement2. Do not explain too much.

If the elements are more specific, such as Frame, Form, input, and so on, we can see that the mshtml namespace is powerful.

 

Attaches a simple application demo, obtains the element through the id, and then obtains the display text of the button.

        private void btnId_Click(object sender, EventArgs e)        {            if (this.document3 != null)            {                IHTMLElement ele = this.document3.getElementById("btnId");                if (ele != null)                {                    var attri = ele.getAttribute("value") as object;                    if (attri != null)                    {                        MessageBox.Show(attri.ToString());                    }                }            }        }

 


Complete Test Project demo: TestActiveX.zip


(If necessary, it will be supplemented later)

Related Article

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.