Speaking of ActiveX, my first instinct is flash, using ActiveX, we can create rich, interactive applications. At the same time, using ActiveX features, we can achieve a seamless connection between JS and ActiveX (including data sharing, and interface calls), with the help of ActiveX to break the browser restrictions, and then achieve more powerful features.
Gossip less, get to the point, and see how to quickly develop a simple password login box:
- Create a new Windows Application project
- Modify the project Properties--the application-to-output type to class library.
- Modify the project Properties--application-to-assembly information--tick ' make assembly COM visible '.
- For ease of debugging (official release, this step can be skipped), tick ' project Properties--Generate COM Interop registration '.
- Delete the default generated Form1 and Program.cs for the project, and create a new control of type UserControl, called Passwordcontrol.
- Adds a Guid for Passwordcontrol.
- Add a Password entry box for Passwordcontrol, with the name Txtpwd.
- Add Getpwd public methods for Passwordcontrol, such as:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Drawing;usingSystem.Data;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Runtime.InteropServices;namespacetestactivex{[Guid ("30a3c1b8-9a9a-417a-9e87-80d0ee827658")] Public Partial classPasswordcontrol:usercontrol { PublicPasswordcontrol () {InitializeComponent (); } Public stringgetpwd () {return This. Txtpwd.text; } }}
- JS calls ActiveX.
<!DOCTYPE HTML><HTMLLang= "en"xmlns= "http://www.w3.org/1999/xhtml"><Head> <MetaCharSet= "Utf-8" /> <title></title> <Scriptlanguage= "JavaScript"type= "Text/javascript"> functionLogin () {Console.info ("Password:" +activiex.getpwd ()); } </Script></Head><Body> <Div> <Objectwidth= " the"Height= "+"ID= "Activiex"ClassID= "clsid:30a3c1b8-9a9a-417a-9e87-80d0ee827658"> </Object> </Div> <inputtype= "button"onclick= "Javascript:login ();"value= "Login" /></Body></HTML>
- At this point, a simple ActiveX is complete.
Test Project Source: Http://files.cnblogs.com/files/08shiyan/TestActiveX.zip
(not to be continued ...)
ActiveX (i) the first simple demo