vs2005做的activex要求客户端安装.net framework,这个很麻烦。

vb的制作、打包工具都很好,所以实验了它。

以下转自网上一篇文章:

最近为了解决一个ActiveX的技术问题,用VB做了一个ActiveX控件,什么功能都没有,

就是测试一下ActiveX的发布,以及版本更新!折腾了两天,总算搞明白其中的一些过程!

顺便记一下,免得忘记!看过一篇文章,介绍了用C#来开发ActiveX的功能,但是C#只能

做托管的程序,需要.net framework在客户端安装后,才能运行!所以,我最终开发,还是

用VB6,VC++6来开发。

      从制作测试ActiveX控件、打包装、发布的步骤如下:
     VB开发ActiveX控件步骤:
     1、创建一个ActiveX Control的项目

     2、绘制ActiveX控件的操作界面,并且编写代码

     3、特别注意:在项目的属性上的Make页,有一个Version Number区域,需要你写当前控件的

           版本号,这个地方和自动下载有密切关系!当你远端的Web浏览器检查到本机的控件版本号

           和服务器上不一样的时候,浏览器就会自动从服务器下载新版本控件进行安装,所以你编译

           的新版本控件一定要改版本号!否则可能导致远程无法更新。

      4、编译ActiveX控件

       ActiveX控件打包步骤:

       本例子以Studio 6.0自带的打包工具为例。      

       1、选择当前选用的VB ActiveX项目进行打包。

       2、其中在选择Package Type的时候有3个选项:

            1)Standard setup package

            2)Internet Package

            3)Dependency File

            选择第二个!

        3、到选择File Source的时候有3个选项:
             1)Include in this cab

             2)download from microsoft web site

             3)download from alternate web site

             以上选项是针对程序包含的每一个相关dll,ocx的,所以,如果你要修改参数,需要一个个文件设置!

            我建议是都选择第一项!因为有些控件从外部更新,可能会遇见证书之类的问题,

            可能导致你的程序无法使用,因此,全部使用本地的是最省心的选择!

            打包过程的其他步骤,没有特别说明的,全部用默认设置!

       4、在发布控件的网站根目录下建一个目录,就叫ActiveX吧,把打包装后的Package目录中的所有文件

             复制到ActiveX目录。

        5、打包完成后修改测试例子htm文件:

             打包完成后,工具会自动产生一个和项目名称一样的htm文件,里面代码如下:

<HTML>
<HEAD>
<TITLE>WebActiveX.CAB</TITLE>
</HEAD>
<BODY>
<!-- If any of the controls on this page require licensing, you must
 create a license package file. Run LPK_TOOL.EXE to create the
 required LPK file. LPK_TOOL.EXE can be found on the ActiveX SDK,
 http://www.microsoft.com/intdev/sdk/sdk.htm. If you have the Visual
 Basic 6.0 CD, it can also be found in the ToolsLPK_TOOL directory.

 The following is an example of the Object tag:

<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
 <PARAM NAME="LPKPath" VALUE="LPKfilename.LPK">
</OBJECT>
-->

<OBJECT ID="ActiveXDrive"
CLASSID="CLSID:F68EC215-0F14-416F-B680-FF8C772A0B47"
CODEBASE="WebActiveX.CAB#version=1,1,0,0">

修改为:

CODEBASE="http://130.50.26.221/ActiveX/WebActiveX.CAB#version=1,1,0,0">
</OBJECT>
</BODY>
</HTML>

注意上面红色字体部分。

客户端IE设置:
1、打开IE->Internet 选项->安全->internet,把安全级设置为低!要注意“自定级别”里面,

     有没有对ActiveX的限制,要是有全放开!

2、要是安装有防火墙软件的,要注意这些软件对http访问有没有限制,要是有全放开!


最后一步:嘿嘿,在另一台电脑上访问发布ActiveX控件的服务器。应该成功了吧!

 

 

我的代码如下:

'write by link
'2009-03-26
'功能:bs中导入等操作之前要选择客户端文件夹,此控件就完成此功能,并返回文件夹名称、文件夹所有文件名字和文件总数

Option Explicit
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (LpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDlist Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Type BROWSEINFO
  hOwner As Long
  pidlroot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As Long
  lparam As Long
  iImage As Long
End Type

Dim rootpath As String  '选择文件夹
Dim cnt As Long '文件总数
Dim files() As String   '所有文件名

Private Function GetFolder(ByVal hWnd As Long, Optional Title As String) As String
    Dim bi As BROWSEINFO
    Dim pidl As Long
    Dim folder As String
    folder = Space(255)
With bi
   If IsNumeric(hWnd) Then .hOwner = hWnd
   .ulFlags = 1
   .pidlroot = 0
   If Title <> "" Then
      .lpszTitle = Title & Chr$(0)
   Else
      .lpszTitle = "选择目录" & Chr$(0)
    End If
End With

pidl = SHBrowseForFolder(bi)
If SHGetPathFromIDlist(ByVal pidl, ByVal folder) Then
    GetFolder = Left(folder, InStr(folder, Chr$(0)) - 1)
Else
    GetFolder = ""
End If
End Function

 
Private Function TreeSearch(ByVal sPath As String, ByVal sFileSpec As String, sFiles() As String) As Long
    Static lngFiles As Long '文件数目
    Dim sDir As String
    Dim sSubDirs() As String '存放子目录名称
    Dim lngIndex As Long
    Dim lngTemp&
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
    sDir = Dir(sPath & sFileSpec)
   '获得当前目录下文件名和数目
    Do While Len(sDir)
      lngFiles = lngFiles + 1
      ReDim Preserve sFiles(1 To lngFiles)
      sFiles(lngFiles) = sPath & sDir
      sDir = Dir
    Loop
   '获得当前目录下的子目录名称
    lngIndex = 0
    sDir = Dir(sPath & "*.*", vbDirectory)
    Do While Len(sDir)
      If Left(sDir, 1) <> "." And Left(sDir, 1) <> ".." Then '' 跳过当前的目录及上层目录
     '找出子目录名
        If GetAttr(sPath & sDir) And vbDirectory Then
          lngIndex = lngIndex + 1
         '保存子目录名
          ReDim Preserve sSubDirs(1 To lngIndex)
          sSubDirs(lngIndex) = sPath & sDir & "\"
        End If
      End If
      sDir = Dir
    Loop
    For lngTemp = 1 To lngIndex
      '查找每一个子目录下文件,这里利用了递归
      Call TreeSearch(sSubDirs(lngTemp), sFileSpec, sFiles())
    Next lngTemp
    TreeSearch = lngFiles
  End Function
 
'弹出对话框
'返回选择文件夹路径
Public Function showDlg() As String
    showDlg = ""
    Dim str() As String
    rootpath = ""
    cnt = 0
   
    rootpath = GetFolder(0, "请选择上传文件夹:")
   
    If rootpath <> "" Then
        Call TreeSearch(rootpath, "*.*", str)
       
        Dim i As Integer
        Dim j As Integer
        j = 0
        Dim strall As String
        For i = 1 To UBound(str)
            If str(i) <> "" Then
                'MsgBox str(i)
                j = j + 1
            End If
        Next
       
        cnt = j '记录文件总数
       
        ReDim Preserve files(1 To cnt)  '重新分配空间
       
        j = 0
        For i = 1 To UBound(str)
            If str(i) <> "" Then
                'MsgBox str(i)
                j = j + 1
                files(j) = str(i)
            End If
        Next
       
        showDlg = rootpath
    Else
        showDlg = ""
    End If
   
End Function

'得到文件夹下文件总数
Public Function getFilesCount() As Long
    getFilesCount = cnt
End Function

'得到选择的文件夹路径
Public Function getSelectedPath() As String
    getSelectedPath = rootpath
End Function

'得到所有文件名
Public Function getAllFiles() As String()
    getAllFiles = files
End Function

'得到第i个文件名
Public Function getFile(i As Long) As String
    If i > 0 And i <= cnt Then
        getFile = files(i)
    Else
        getFile = ""
    End If
End Function


''示例或测试代码
'Private Sub Command1_Click()
'    Dim root As String
'    root = showDlg()
'
'    Dim count As Long
'    count = getFilesCount()
'    Dim s() As String
'    ReDim Preserve s(1 To count)
'    s = getAllFiles()
'    Dim i As Long
'    For i = 1 To count
'        MsgBox s(i)
'    Next
'End Sub

 

调用如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="dirselectxtestweb._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>dirselectx测试网页</title>
</head>
<body>
        <font face = arial size = 1><OBJECT id = "dirselect1" name = "dirselect1"  CLASSID="CLSID:0C5B1166-FEFB-42D3-B517-C579A7A2BB42" CODEBASE="dirselectx.CAB#version=1,0,0,0">
        </OBJECT>
        </font> 
    <form name = "frm" id = "frm" runat=server>
        <input type=text ></asp:Label>
       
    </form>
</body>

<script language = "javascript">
function doScript()
{
    //调用对话框,返回选择文件夹路径,或者空值
 var t = dirselect1.showDlg();
 //alert(t);
 if(t!="")
 {
  var i=1;
  //该文件夹下总共有文件数
  var cnt = dirselect1.GetFilesCount();
  alert(cnt);  
  
  //var array = new Array(cnt);

        var allstr = "";
  for(i;i<=cnt;i++)
  {
      //得到第i个文件名
   var str = dirselect1.GetFile(i);
   //alert(str);
   if(i==1)
   {
       allstr = str;
   }
   else
   {
       allstr = allstr + "*" + str;
   }
  }
  
  //通过表单回传到服务器
  document.all.backserverstr.value = allstr;
  //alert("OK");
 } 

}
</script>
</html>

相关文章:

  • 2021-08-25
  • 2021-11-30
  • 2022-12-23
  • 2021-12-29
  • 2021-11-17
  • 2022-12-23
  • 2022-02-10
猜你喜欢
  • 2021-12-27
  • 2021-10-01
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案