代码之家  ›  专栏  ›  技术社区  ›  codeulike

在XP和Vista中工作的VBScript文件打开对话框?

  •  4
  • codeulike  · 技术社区  · 16 年前

    在XP中,可以将VBScript与用户帐户.CommonDialog对象以打开文件打开对话框( as described here ),但显然 this does not work under Vista .

    是否有一个VBScript方法用于文件打开对话框,这两种方法都适用?

    或者哪怕是一个可以很好地为Vista工作的?

    免责声明:我是一个适当的程序员,诚实,通常不与VBScript工作-我问这个问题'为朋友'。

    1 回复  |  直到 16 年前
        1
  •  1
  •   ArBR    15 年前

    你可以创建一个简单的 点网组件 这暴露了 ,这样您就可以在 VBScript语言 (或任何 技术)。

    • (1) 创建一个dot-net库类型的项目,公开您想要成为COM互操作性的类(添加 分类界面 属性)。这个 分类界面 属性必须设置为 自动对偶 所以你可以通过 后期装订 .
    • (2) 标记 COM互操作性注册 选中“项目属性”对话框的“生成”选项卡中的复选框。
    • (3) 构建项目,以便可以正确注册组件(您可以选择创建 设置项目

    ...

    namespace WinUtility
    {
        [ComVisible(true), Guid("32284FD3-417E-45fc-A4A0-9344C489053B"),
         ClassInterface(ClassInterfaceType.AutoDual)]
        public class WinDialog
        {
            public string ShowOpenFileDialog()
            {
                string result = string.Empty;
                OpenFileDialog d = new OpenFileDialog();
                if (d.ShowDialog() == DialogResult.OK) { result = d.FileName; }
                return result;
            }
        }
    }
    

    注册组件后,您可以从VBScript实例化它:

    dim wnd_helper, file_name
    Set wnd_helper = CreateObject("WinUtility.WinDialog")
    file_name = wnd_helper.ShowOpenFileDialog()
    if trim(file_name) <> "" then
        msgbox "file: " + file_name
    else
        msgbox "No file selected."
    end if
    
    推荐文章