active 控件(ocx和dll)的编写和调用。

用vb编写一个简单的ocx和dll,这2种都是属于active类型的。

active ocx 和active dll的区别,可以简单的认为ocx是用来实现显示界面用的,而dll是实现函数调用的。

1.打开vb建立active ocx,在usercontrol上添加一个text1控件。

编写代码:

Public Property Get Text() As String Text = Text1.Text End Property Public Property Let Text(ByVal value As String) Text1.Text = value PropertyChanged "Text" End Property Private Sub UserControl_ReadProperties(PropBag As PropertyBag) '读属性 Text1.Text = PropBag.ReadProperty("Text", "Text1") End Sub Private Sub UserControl_WriteProperties(PropBag As PropertyBag) '写属性 PropBag.WriteProperty "Text", Text1.Text, "Text1" End Sub

2.建立index.htm

代码:

<html> <head> <mce:script type= "text/javascript" language="javascript"><!-- function t(){ var k=document.getElementById("ocxtype").text; alert(k); } // --></mce:script> </head> <body> <FORM ACTION="s.asp" METHOD="post"> <OBJECT id=ocxtype height=100px width=300px classid=CLSID:D6F5075B-250E-47BF-9CF4-556D1E1E251A> <PARAM NAME="_ExtentX" VALUE="7567"> <PARAM NAME="_ExtentY" VALUE="3969"> <PARAM NAME="Text" VALUE="pathtext"> </OBJECT> <br> <input type=text value="ok" name="ok" οnclick="t();"/> FirstName:<INPUT TYPE="TEXT" NAME="FirstName"> LastName:<INPUT TYPE="TEXT" NAME="LastName"> <INPUT TYPE="SUBMIT" VALUE="Send"> </FORM> </body> </html>

classid=CLSID:D6F5075B-250E-47BF-9CF4-556D1E1E251A

是ocx的id,这个去注册表找的。也可以通过其他方法查找。

asp:代码

<%
response.write "count=" & request.form.count & "<br>"
For Each objItem In Request.Form
Response.Write objItem & "=" & Request.Form(objItem) & "<br>"
next
response.write "testtext=" & request.form("testtext") & "<br>"
'obj = Server.CreateObject("Text.u")
'temp=obj.text
response.write temp & "<br>"
%>

========================下面是查看ocx的属性和方法的脚本====================================

<html>
<head>
<title>查看OCX的属性和方法的脚本</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
var flag=true
function showall(){
alist = new Array();
newocx();
list1.value = "";
list2.value = "";
list1.value = ocxtype.outerHTML;
j = 0;
for (i in ocxtype)
{
alist[j] = i;
j++;
}
for (i = 0; i < alist.length; i++)
for (j = (alist.length-1); j > 0; j--)
{
if (alist[j] < alist[j-1])
{
temps = alist[j];
alist[j] = alist[j-1];
alist[j-1] = temps;
}
}
for (i = 0; i < alist.length; i++)
list2.value += alist[i] + "/n";
alert("共有 "+alist.length+" 个属性方法")
}
function newocx()
{
ocxfield.innerHTML = "<OBJECT ID='ocxtype' WIDTH='0px' HEIGHT='0px'" +
"CLASSID='CLSID:" + ocxid.value + "'></OBJECT>";
}
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">

<div align="center">
<p>classid
<input type="text" id="ocxid" style="width:400" value="F3A614DC-ABE0-11d2-A441-00C04F795683" οnchange="jscript:flag=true">
<input type="button" id="look" value="查看" οnclick="showall()">
</p>
<table width="75%" border="1">
<tr>
<td height="24">
<div align="center">html中的写法</div>
</td>
<td height="24">
<div align="center">OCX中的属性事件</div>
</td>
</tr>
<tr>
<td>
<textarea id="list1" style="width: 500px; height: 400px;" readonly></textarea>
</td>
<td>
<textarea id="list2" style="width:250px; height:400px;" readonly></textarea>
</td>
</tr>
</table>
</div>
<div id="ocxfield">
</div>
</body>
</html>
=================================================================================

建立active dll

1.编写代码:

publicfunctionadd(a as integer,b as integer) as integer

add=a+b

end function

2.编写代码html

<script>

function add(a,b)

var sum=new ActiveXObject("工程名.类名");

sum.add(a,b);

end function

</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值