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- ...
随机推荐
- CDN解决方案
帝联cdn 这算不算是打广告呢?
- Finger Trees: A Simple General-purpose Data Structure
http://staff.city.ac.uk/~ross/papers/FingerTree.html Summary We present 2-3 finger trees, a function ...
- NodeJS入门(四)—— path对象
很快Node就会迎来4.0的时代,届时将并入现有的iojs,所以先前写过的iojs入门系列直接更名为NodeJS入门. 本篇开始将逐个介绍Node的各主要模块,依循API文档走一遍,但会给出比API文 ...
- Hadoop学习笔记—9.Partitioner与自定义Partitioner
一.初步探索Partitioner 1.1 再次回顾Map阶段五大步骤 在第四篇博文<初识MapReduce>中,我们认识了MapReduce的八大步凑,其中在Map阶段总共五个步骤,如下 ...
- 搭建域服务器和DNS
标签:SQL SERVER/MSSQL SERVER/数据库/DBA/域控制器 概述 因为很多高性能高可用方案都会在域环境中组建,所以了解创建域的一些知识对搭建那些高可用方案很有必要. 环境:wind ...
- 在Windows中安装Memcached
Memcached是一个高并发的内存键值对缓存系统,它的主要作用是将数据库查询结果,内容,以及其它一些耗时的计算结果缓存到系统内存中,从而加速Web应用程序的响应速度. Memcached最开始是作为 ...
- OpenCASCADE Camera
OpenCASCADE Camera eryar@163.com Abstract. OpenCASCADE introduce a new class Graphic3d_Camera for th ...
- 针对格式文件,Python读取一定大小的文件内容
由数据库导出的数据是格式化数据,如下所示,每两个<REC>之间的数据是一个记录的所有字段数据,如<TITLE>.<ABSTRACT>.<SUBJECT_COD ...
- HTTP的长连接和短连接——Node上的测试
本文主要从实践角度介绍长.短连接在TCP层面的表现,借助Node.JS搭建后台服务,使用WinHTTP.Ajax做客户端请求测试,最后简单涉及WebSocket. 关键字:长连接.短连 ...
- 亚马逊云架设WordPress博客
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 这篇文章介绍如何在亚马逊云架设WordPress博客.最强的云,加上最流行的建站工 ...