Before learning Internet Explorer programming, you learned that MSHTML, IE implements the mark (TAG) in the HTML language, and encapsulated by the MSHTML.dll. MSHTML is a COM component-based object model whose interface is based on iDispatch. For the introduction of MSHTML, please see
MSDN documentation, Chinese version can refer to the article below.
About MSHTML
All interfaces of the access dynamic HTML (DHTML) object model are based on iDispatch, and is also the basis for the object model used for scripts. Therefore, anyone to manipulate the object model is to familiarize with the configuration and functionality of the Object Model References defined in the dynamic HTML introduction and the object model included in the MSHTML.
MSHTML Reference Interface and Script Object This section describes how objects are mapped to the interface in the DHTML object model. For example, using this map, you can see the IHTMLDocument2 interface map to the document object. Further research on the interface illustrates how to access objects of objects via GET_ and PUT_ methods. The object's method is mapped to the method of available interfaces, and events can be captured with standards automated connection points.
How to make an object of an object model interface In colbartn, driller, and Walkall examples, these examples are on the COLBTN sample source code page, a DRILLER sample source code page, and a Walkall Example Source code page.
Use the advice to use the interface to obtain the topic related to the document interface
Advice using the interface
Typically, anything that can be done with scripts in documentation can be done by using an interface manipulation object model. Therefore, it is recommended that the developer should use the script design function prototype in an HTML document before writing the code using the object model interface.
The following HTML examples illustrate how to use the script navigation document ALL collection and get the tag name of each element of the document. Equivalent The Object Model Interface Microsoft (R) Visual C (R) code presentation is on the DRILLER Example Source Code Page and Walkall Example Source Code Page.
example
HEAD>
Function loaded ()
{
VAR C = Document.all.length;
Var i;
For (i = 0; i { Spantags.innerhtml = spantags.innerhtml Document.all.Item (i) .tagname " } } Script>
";
span>
Body>
Html>
Get a document interface
To start using an object model interface, you have to get the IHTMLDocument2 interface from the document. Once you have this interface, you can access all the elements in the document. How to depends on how your application is implemented. Each of the following occasions needs to be obtained in a different way.
An instance of integrating a browser control while integrating MSHTML. A Microsoft ActiveX (R) control included from a web page.
Document interface when integrated MSHTML
When you integrate a MSHTML object, create an object using CoCreateInstance. Once an object is created, you can call its QueryInterface method, request IID_IHTMLDocument2. Walkall Example Sample Page The Walkall sample illustrates how it is.
Document interface when integrated browser control
When integrating browser controls, perform the following steps to get a document interface:
Call iWebBrowser2 :: get_document to get the IDispatch interface of the document. (Translator Note: The gethtmlDocument method of the MFC, the DOCUMENT property of the browser control, or the DOM attribute of the DHTMLEDIT control can also be used to obtain the document interface. Get the document interface from the ActiveX control
Access dynamic HTML section of the ActiveX document explains how to get a document interface from the ActiveX (R) control.
Use document interface
Use document interface
Once you get a document interface, you can use any of the IHTMLDocument2 interface to get or modify the properties of the document. This usually includes some IHTMLELEMENTCOLLECTION interfaces from different elements contained from the document.
A very common collection of objects is all set objects. ALL collection object is obtained by using IHTMLDocument2 :: all (Translator Note: Original, it seems to be changed to get_all) method. This method returns an IHTMLELEMEMENTCOLLECTION interface for all elements of the document. Then you can enumerate the elements using the IHTMLELEMENTCOLLECTION :: Item method. IHTMLELEMENTCOLLECTION :: Item method provides you with an iDispatch pointer you can call QueryInterface, request IID_IHTMLELEMENT. This will give you an IHTMLEMENT interface pointer that you can use to get or set information for individual elements.
Most elements provide an interface to manipulate the particular element. These elements related interface names have IHTMLXXXELEMENT format, where xxxx is the name of the element. To obtain an element-related interface, you can call QueryInterface on the IHTMLELEMENT interface, request the interface related to the required elements. For example, an IMG element provides an IHTMLIMGELEMENT interface to specifically manipulate the IMG element. To see an interface list related to the available elements, view the interface list of interfaces and script objects.