ActiveX(四) mshtml 命名空间 重要接口简介
在上一篇随笔 ActiveX(三)ActiveX 调用 Js 中,我们已经可以获得js中window对象的强类型接口、即 mshtml.IHTMLWindow2 ,通过该接口、我们可以调用js函数。那么我们再试一试其他的方法呢,看看结果是否符合预期:
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());
}
}
哈哈,试了一下,没有问题。 但是经过使用发现 location 属性是只读的,并且、如果通过反射强制设置 location 属性,则会抛出异常哦。
现在知道了 window , 那 document 呢? mshtml 命名空间中有没有提供相应的接口呢? 经过查找发现、document实现了如下的两个接口:
[Guid("332C4425-26CB-11D0-B483-00C04FD90119")]
[TypeLibType()]
public interface IHTMLDocument2 : IHTMLDocument
{
[DispId()]
IHTMLElement activeElement { get; }
[DispId()]
dynamic alinkColor { get; set; }
[DispId()]
IHTMLElementCollection all { get; }
[DispId()]
IHTMLElementCollection anchors { get; }
[DispId()]
IHTMLElementCollection applets { get; }
[DispId(-)]
dynamic bgColor { get; set; }
[DispId()]
IHTMLElement body { get; }
[DispId()]
string charset { get; set; }
[DispId()]
string cookie { get; set; }
[DispId()]
string defaultCharset { get; set; }
[DispId()]
string designMode { get; set; }
[DispId()]
string domain { get; set; }
[DispId()]
IHTMLElementCollection embeds { get; }
[DispId()]
bool expando { get; set; }
[DispId(-)]
dynamic fgColor { get; set; }
[DispId()]
string fileCreatedDate { get; }
[DispId()]
string fileModifiedDate { get; }
[DispId()]
string fileSize { get; }
[DispId()]
string fileUpdatedDate { get; }
[DispId()]
IHTMLElementCollection forms { get; }
[DispId()]
FramesCollection frames { get; }
[DispId()]
IHTMLElementCollection images { get; }
[DispId()]
string lastModified { get; }
[DispId()]
dynamic linkColor { get; set; }
[DispId()]
IHTMLElementCollection links { get; }
[DispId()]
HTMLLocation location { get; }
[DispId()]
string mimeType { get; }
[DispId()]
string nameProp { get; }
[DispId(-)]
dynamic onafterupdate { get; set; }
[DispId(-)]
dynamic onbeforeupdate { get; set; }
[DispId(-)]
dynamic onclick { get; set; }
[DispId(-)]
dynamic ondblclick { get; set; }
[DispId(-)]
dynamic ondragstart { get; set; }
[DispId(-)]
dynamic onerrorupdate { get; set; }
[DispId(-)]
dynamic onhelp { get; set; }
[DispId(-)]
dynamic onkeydown { get; set; }
[DispId(-)]
dynamic onkeypress { get; set; }
[DispId(-)]
dynamic onkeyup { get; set; }
[DispId(-)]
dynamic onmousedown { get; set; }
[DispId(-)]
dynamic onmousemove { get; set; }
[DispId(-)]
dynamic onmouseout { get; set; }
[DispId(-)]
dynamic onmouseover { get; set; }
[DispId(-)]
dynamic onmouseup { get; set; }
[DispId(-)]
dynamic onreadystatechange { get; set; }
[DispId(-)]
dynamic onrowenter { get; set; }
[DispId(-)]
dynamic onrowexit { get; set; }
[DispId(-)]
dynamic onselectstart { get; set; }
[DispId()]
IHTMLWindow2 parentWindow { get; }
[DispId()]
IHTMLElementCollection plugins { get; }
[DispId()]
string protocol { get; }
[DispId()]
string readyState { get; }
[DispId()]
string referrer { get; }
[DispId()]
dynamic Script { get; }
[DispId()]
IHTMLElementCollection scripts { get; }
[DispId()]
string security { get; }
[DispId()]
IHTMLSelectionObject selection { get; }
[DispId()]
HTMLStyleSheetsCollection styleSheets { get; }
[DispId()]
string title { get; set; }
[DispId()]
string url { get; set; }
[DispId()]
dynamic vlinkColor { get; set; } [DispId()]
void clear();
[DispId()]
void close();
[DispId()]
IHTMLElement createElement(string eTag);
[DispId()]
IHTMLStyleSheet createStyleSheet(string bstrHref = "", int lIndex = -);
[DispId()]
IHTMLElement elementFromPoint(int x, int y);
[DispId()]
bool execCommand(string cmdID, bool showUI = false, object value = Type.Missing);
[DispId()]
bool execCommandShowHelp(string cmdID);
[DispId()]
dynamic open(string url = "text/html", object name = Type.Missing, object features = Type.Missing, object replace = Type.Missing);
[DispId()]
bool queryCommandEnabled(string cmdID);
[DispId()]
bool queryCommandIndeterm(string cmdID);
[DispId()]
bool queryCommandState(string cmdID);
[DispId()]
bool queryCommandSupported(string cmdID);
[DispId()]
string queryCommandText(string cmdID);
[DispId()]
dynamic queryCommandValue(string cmdID);
[DispId()]
string toString();
[DispId()]
void write(params object[] psarray);
[DispId()]
void writeln(params object[] psarray);
}
IHTMLDocument2
[Guid("3050F485-98B5-11CF-BB82-00AA00BDCE0B")]
[TypeLibType()]
public interface IHTMLDocument3
{
[DispId()]
string baseUrl { get; set; }
[DispId(-)]
dynamic childNodes { get; }
[DispId(-)]
string dir { get; set; }
[DispId()]
IHTMLElement documentElement { get; }
[DispId()]
bool enableDownload { get; set; }
[DispId()]
bool inheritStyleSheets { get; set; }
[DispId(-)]
dynamic onbeforeeditfocus { get; set; }
[DispId(-)]
dynamic oncellchange { get; set; }
[DispId(-)]
dynamic oncontextmenu { get; set; }
[DispId(-)]
dynamic ondataavailable { get; set; }
[DispId(-)]
dynamic ondatasetchanged { get; set; }
[DispId(-)]
dynamic ondatasetcomplete { get; set; }
[DispId(-)]
dynamic onpropertychange { get; set; }
[DispId(-)]
dynamic onrowsdelete { get; set; }
[DispId(-)]
dynamic onrowsinserted { get; set; }
[DispId(-)]
dynamic onstop { get; set; }
[DispId()]
IHTMLDocument2 parentDocument { get; }
[DispId()]
string uniqueID { get; } [DispId(-)]
bool attachEvent(string @event, object pdisp);
[DispId()]
IHTMLDocument2 createDocumentFragment();
[DispId()]
IHTMLDOMNode createTextNode(string text);
[DispId(-)]
void detachEvent(string @event, object pdisp);
[DispId()]
IHTMLElement getElementById(string v);
[DispId()]
IHTMLElementCollection getElementsByName(string v);
[DispId()]
IHTMLElementCollection getElementsByTagName(string v);
[DispId()]
void recalc(bool fForce = false);
[DispId()]
void releaseCapture();
}
IHTMLDocument3
在 IHTMLDocument3 中 发现的比较重要的几个方法,是 IHTMLDocument2 中没有的。
[DispId()]
IHTMLElement getElementById(string v);
[DispId()]
IHTMLElementCollection getElementsByName(string v);
[DispId()]
IHTMLElementCollection getElementsByTagName(string v);
document 有了,那 element 呢? element 似乎有点多、一共有四个,常用的有两个、分别为:IHTMLElement、IHTMLElement2。不做过多解释。
如果把 element 再具体一些、像 Frame、 Form、input 等等 都有相对应的接口的,由此可以看出 mshtml 命名空间强大之处。
附一个简单应用demo,通过id获取element,然后得到按钮的显示文本。
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());
}
}
}
}
完整的测试项目demo: TestActiveX.zip
(暂完,如有需要后续补充)
ActiveX(四) mshtml 命名空间 重要接口简介的更多相关文章
- [Effective Java]第四章 类和接口
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- SQLite3 C/C++ 开发接口简介
SQLite3 C/C++ 开发接口简介 1.0 总览 SQLite3是SQLite一个全新的版本,它虽然是在SQLite 2.8.13的代码基础之上开发的,但是使用了和之前的版本不兼容的数据库格式和 ...
- ADI高速信号采集芯片与JESD204B接口简介
ADI高速信号采集芯片与JESD204B接口简介 JESD204B接口 介绍: JEDEC Standard No. 204B (JESD204B)—A standardized serial int ...
- Lock接口简介
在Java多线程编程中,我们经常使用synchronized关键字来实现同步,控制多线程对变量的访问,来避免并发问题. 但是有的时候,synchronized关键字会显得过于沉重,不够灵活.synch ...
- 如何MSHTML命名空间解析HTML文件(MSHTML::IHTMLDocument2Ptr 提示错误)
1.创建Win32或MFC工程. 2.在预编译或需要使用MSHTML命名空间的头文件中添加以下语句: #include <atlbase.h> #include <Mshtml ...
- iOS中常用的四种数据持久化方法简介
iOS中常用的四种数据持久化方法简介 iOS中的数据持久化方式,基本上有以下四种:属性列表.对象归档.SQLite3和Core Data 1.属性列表涉及到的主要类:NSUserDefaults,一般 ...
- Linux中的IO复用接口简介(文件监视?)
I/O复用是Linux中的I/O模型之一.所谓I/O复用,指的是进程预先告诉内核,使得内核一旦发现进程指定的一个或多个I/O条件就绪,就通知进程进行处理,从而不会在单个I/O上导致阻塞. 在Linux ...
- java多线程Lock接口简介使用与synchronized对比 多线程下篇(三)
前面的介绍中,对于显式锁的概念进行了简单介绍 显式锁的概念,是基于JDK层面的实现,是接口,通过这个接口可以实现同步访问 而不同于synchronized关键字,他是Java的内置特性,是基于JVM的 ...
- SoapUI SoapUI测试WebService协议接口简介
SoapUI测试WebService协议接口简介 by:授客 QQ:1033553122 1. 创建项目,入口:File -> New SOAP Project,或者右键默认项目Project- ...
随机推荐
- Unity 5.3.5p8 C#编译器升级
Unity 5.3.5p8的C#编译器升级 注意:该版本是单独升级C#编译器的测试版!请使用文中提供的下载链接! 基于Unity 5.3.5p8的C#编译器升级!下载链接 试用该版本前请先备份项目,遇 ...
- 非常郁闷的 .NET中程序集的动态加载
记载这篇文章的原因是我自己遇到了动态加载程序集的问题,而困扰了一天之久. 最终看到了这篇博客:http://www.cnblogs.com/brucebi/archive/2013/05/22/Ass ...
- 【译】PHP的变量实现(给PHP开发者的PHP源码-第三部分)
文章来自:http://www.aintnot.com/2016/02/12/phps-source-code-for-php-developers-part3-variables-ch 原文:htt ...
- node基本理念(事件、多线程、进程)
关于node的几点理解: 1.所谓的node单线程,是指node的event loop,也就是我们的业务脚本是跑在一个单线程中的,可以理解为主线程: 2.若存在IO操作,例如文件.网络,是单独在线程里 ...
- Nova PhoneGap框架 第五章 文件结构
一个好的项目架构必然有着合理的文件结构,如果一个项目的文件组织混乱,那么可以断言一定是项目架构有问题. 合理的文件结构能够帮你更清晰的管理你的文件,并且当需要添加新的文件的时候,你的程序员很清楚应该加 ...
- 使用VS+VisualGDB编译调试Linux程序
Linux程序开发变得越来越多,越来越多的程序.产品需要跨平台,甚至有些开源项目只支持Linux平台,所以掌握Linux开发变得越来越重要. 但是对于习惯了Windows下的开发,使用了VS这个宇宙第 ...
- Go语言实战 - revel框架教程之MongDB的最佳搭档revmgo
由于revel框架本身对于model层的编写没有提供任何指导,所以在设计这部分的时候就有些犹豫,反复斟酌到底怎样才算是最佳实践. 我在做山坡网的时候刚开始也纠结了一下,拿不准mongodb的sessi ...
- JavaWeb配置外部应用的两种方式
原来我们的项目放到webapps下,现在放到外面,也希望tomcat可以找到它!把应用放到tomcat之外,这就是外部应用了.应用已经不在tomcat中了,这时我们需要在tomcat中配置外部应用的位 ...
- SQL 联合查询 + XML解析
(select a.EBILLNO, a.EMPNAME, a.APPLYDATE, b.HS_NAME, ), ),'') as SUMMARY, cast(c.XmlData as XML).va ...
- [转]PHP的执行流程,PHP扩展加载过程
原文:http://www.imsiren.com/archives/535 为了以后能开发PHP扩展..就一定要了解PHP的执行顺序..这篇文章就是为C开发PHP扩展做铺垫. web环境 我们假设为 ...