Browser extension series-add built-in Script objects to msthml, including custom events]

Source: Internet
Author: User

Calibri; MSO-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin "> usage:

Mso-fareast-font-family:; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; mso-hansi-theme-font: minor-latin "> in the program, use WebBrowsermso-fareast-font-family: mso;-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; mso-hansi-theme-font: minor-latin "> or related controls such as axWebBrowsermso-fareast-font-family:; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; mso-hansi-theme-font: minor-latin ">. Open the local htmlmso-fareast-font-family:; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; mso-hansi-theme-font: minor-latin "> file, you can go to htmlmso-fareast-font-family:; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; MSO-Hansi-theme-Font: minor-Latin ">. netmso-Fareast-font-family:; MSO-Fareast-theme-Font: minor-Fareast; MSO-Hansi-font-family:
Calibri; MSO-Hansi-theme-Font: minor-Latin "> class defined in
Explorer servermso-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: calibri; MSO-Hansi-theme-Font: minor-Latin "> interoperability. You can also make full use of htmlmso-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: calibri; MSO-Hansi-theme-Font: minor-Latin "> efficient and simple design interface, you can also implement some complex features.

Calibri; MSO-ascii-theme-Font: minor-Latin; MSO-Fareast-font-family:; MSO-Fareast-theme-Font:
Minor-Fareast; MSO-Hansi-font-family: calibri; MSO-Hansi-theme-Font: minor-Latin "> Implementation:


Code
Public class scriptevent
{
// System. _ comobject object
Private object eventobject;
 
Public object eventobect
{
Get {return this. eventobject ;}
Set {This. eventobject = value ;}
}
 
Public object execute ()
{
If (null = eventObject)
Return null;
// Guid of the FunctionInstance interface in JScript. dll
Guid fun_gid = new Guid ("{3EEF9758-35FC-11D1-8CE4-00C04FC2B093 }");
Type functionInstance = Type. GetTypeFromCLSID (fun_gid );
Object rev;
Rev = functionInstance. InvokeMember ("call", BindingFlags. InvokeMethod | BindingFlags. NonPublic, null, eventObject, null );
Return rev;
}

 

ScriptEvent; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family:
; Mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri;
Mso-hansi-theme-font: minor-latin "> class encapsulates script events.

Mso-ascii-theme-font: minor-latin; mso-fareast-font-family:; mso-fareast-theme-font:
Minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin "> the usage is as follows:


Code
[ComVisibleAttribute (true)]
Public class ScriptObject
{
Private Window window;
Private ScriptEvent onClickEvent;
 
Public ScriptObject (Window window)
{
This. window = window;
OnClickEvent = new ScriptEvent ();
}
 
Public string WindowTitle
{
Get {return window. Title ;}
}
 
Public double Add2 (double num1, double num2)
{
Return num1 + num2;
}
 
Public object onClick
{
Get {return onClickEvent. EventObect ;}
Set {onClickEvent. EventObect = value ;}
}
 
Public void OnClick ()
{
OnClickEvent. Execute ();
}

 

18.0pt; font-family: New; MSO-Hansi-font-family: "Times New Roman"; MSO-bidi-font-family:
"Times New Roman"; color: #010001; font-weight: normal; MSO-bidi-font-weight: bold;
MSO-no-proof: Yes '> onclick1820.pt; font-family: New; MSO-Hansi-font-family: "Times New Roman"; MSO-bidi-font-family:
"Times New Roman"; color: #010001; font-weight: normal; MSO-bidi-font-weight: bold;
The MSO-no-proof: Yes '> attribute corresponds to the MSO-Hansi-font-family: "Times New Roman"; MSO-bidi-font-family: "Times New Roman ";
Color: # 2b91af; MSO-no-proof: Yes '> scriptobjectmso-bidi-font-size: 18.0pt; font-family: New; MSO-Hansi-font-family: "Times New Roman ";
MSO-bidi-font-family: "Times New Roman"; color: #010001; font-weight: normal;
MSO-bidi-font-weight: bold; MSO-no-proof: Yes '> onclick event of the class. In the script, you can assign a function instance to The onclick attribute of this class.

Mso-fareast-font-family:; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; mso-hansi-theme-font: minor-latin "> because in javascriptmso-fareast-font-family:; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; mso-hansi-theme-font: minor-latin "> events are not equivalent. netmso-fareast-font-family:; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; mso-hansi-theme-font: minor-latin "> event, specifically, javascriptmso-fareast-font-family:; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family:
Calibri; mso-hansi-theme-font: minor-latin "> multiple events cannot be bound. Therefore, an event can be implemented as a function object by using com viewerCalibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family:; mso-fareast-theme-font:
Minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin "> View System32Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family:; mso-fareast-theme-font:
Minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin "> Jscript. dllCalibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family:; mso-fareast-theme-font:
Minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin ">, this object corresponds to the mso-bidi-font-family: "Times New Roman"; color: green; mso-no-proof: yes '> FunctionInstancemso-bidi-font-family: "Times New Roman"; color: black; mso-themecolor: text1;
Mso-no-proof: yes '> interface. Therefore, reflection is used to construct this interface and then the real script function is called.

Mso-bidi-font-family: "Times New Roman"; color: black; mso-themecolor: text1;
Mso-no-proof: yes '>

 

Mso-bidi-font-family: "Times New Roman"; color: black; mso-themecolor: text1;
Mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;
Mso-no-proof: yes '> download the code http://files.cnblogs.com/chinese-zmm/scriptobjectdemo.rar.

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.