在上一篇随笔 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 命名空间 重要接口简介的更多相关文章

  1. [Effective Java]第四章 类和接口

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. SQLite3 C/C++ 开发接口简介

    SQLite3 C/C++ 开发接口简介 1.0 总览 SQLite3是SQLite一个全新的版本,它虽然是在SQLite 2.8.13的代码基础之上开发的,但是使用了和之前的版本不兼容的数据库格式和 ...

  3. ADI高速信号采集芯片与JESD204B接口简介

    ADI高速信号采集芯片与JESD204B接口简介 JESD204B接口 介绍: JEDEC Standard No. 204B (JESD204B)—A standardized serial int ...

  4. Lock接口简介

    在Java多线程编程中,我们经常使用synchronized关键字来实现同步,控制多线程对变量的访问,来避免并发问题. 但是有的时候,synchronized关键字会显得过于沉重,不够灵活.synch ...

  5. 如何MSHTML命名空间解析HTML文件(MSHTML::IHTMLDocument2Ptr 提示错误)

    1.创建Win32或MFC工程. 2.在预编译或需要使用MSHTML命名空间的头文件中添加以下语句: #include <atlbase.h>    #include <Mshtml ...

  6. iOS中常用的四种数据持久化方法简介

    iOS中常用的四种数据持久化方法简介 iOS中的数据持久化方式,基本上有以下四种:属性列表.对象归档.SQLite3和Core Data 1.属性列表涉及到的主要类:NSUserDefaults,一般 ...

  7. Linux中的IO复用接口简介(文件监视?)

    I/O复用是Linux中的I/O模型之一.所谓I/O复用,指的是进程预先告诉内核,使得内核一旦发现进程指定的一个或多个I/O条件就绪,就通知进程进行处理,从而不会在单个I/O上导致阻塞. 在Linux ...

  8. java多线程Lock接口简介使用与synchronized对比 多线程下篇(三)

    前面的介绍中,对于显式锁的概念进行了简单介绍 显式锁的概念,是基于JDK层面的实现,是接口,通过这个接口可以实现同步访问 而不同于synchronized关键字,他是Java的内置特性,是基于JVM的 ...

  9. SoapUI SoapUI测试WebService协议接口简介

    SoapUI测试WebService协议接口简介 by:授客 QQ:1033553122 1. 创建项目,入口:File -> New SOAP Project,或者右键默认项目Project- ...

随机推荐

  1. Javascript基础回顾 之(一) 类型

    本来是要继续由浅入深表达式系列最后一篇的,但是最近团队突然就忙起来了,从来没有过的忙!不过喜欢表达式的朋友请放心,已经在写了:) 在工作当中发现大家对Javascript的一些基本原理普遍存在这里或者 ...

  2. ENode框架Conference案例分析系列之 - 订单处理减库存的设计

    前言 前面的文章,我介绍了Conference案例的业务.上下文划分.领域模型.架构,以及代码整体流程.接下来想针对案例中一些重要的场景,分别做进一步的分析.本文想先介绍一下Conference案例的 ...

  3. 使用Guava EventBus构建publish/subscribe系统

    Google的Guava类库提供了EventBus,用于提供一套组件内publish/subscribe的解决方案.事件总线EventBus,用于管理事件的注册和分发.在系统中,Subscribers ...

  4. WPF PlacementTarget技巧

    <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winf ...

  5. 花一分钟来看看Worktile是如何为团队协作而生的

    团队协作,我们想的更深.更远.更多,花一分钟来看看我们特别奉献的故事,然后去注册一个账号,邀请小伙伴一起来工作,你会体会Worktile才是真正懂你的协作方式.

  6. SQLyog图形化l数据库的操作和学习

    1:首先SQLyog作为mysql的图形化操作工具,是一个收费的工具,但是在天朝大国,任何收费的软件都可以被破解,具体软件的安装不做多叙述,支持正版,毕竟作为一个开发人员,辛辛苦苦开发出来的软件,还指 ...

  7. JavaScript 函数的两种声明方式

    1.函数声明的方式 JavaScript声明函数有两种选择:函数声明法,表达式定义法. 函数声明法 function sum (num1 ,num2){ return num1+num2 } 表达式定 ...

  8. android 画虚线,虚线圆

    Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE);   paint.set ...

  9. removeClass 按钮点击添加class效果

    html代码: <div class="game"> <span class="active">全部</span> < ...

  10. Ado net Source 用法

    Ado net Source 是用于获取数据源的,使用的connection manager是 ado net connection. Ado Net Source 的Data Access Mode ...