• Silverlight 访问外部程序


    在silverlight中调用外部程序的几种方法总结如下:
     
    1.silverlight不支持oob模式的时候,silverlight调外部应用程序只能通过activex来实现。
     
       大致方法如下,之前写的一个:
     
           var idropItems;
            var clsid;
            var plugin;
            var currentDivIndex;
            jQuery(document).ready(function() {
                idropItems = window.parent.GetIDropItems();
                if (idropItems.length > 0) {
     
                    BuildDivContainer();
     
                    //activex的clsid,
     
                    clsid = "clsid:21E0CB95-1198-4945-A3D2-4BF804295F78";
                    $("#Pagination").pagination(idropItems.length, {
                        num_edge_entries: 2,
                        num_display_entries: 8,
                        items_per_page: 8,
                        next_text: "",
                        prev_text: "",
                        callback: pageselectCallback
                    });
                }
            });
            function pageselectCallback(page_id, jq) {
                BuildIDropItems(page_id);
            }
    
     
       function BuildIDropItems(pageIndex) {
     
                $("#c_" + currentDivIndex).hide();
                if ($("#c_" + pageIndex).attr("loaded") == "0") {
                    var itemIndex = pageIndex * 8;
                    var html = "";
                    for (var i = itemIndex; i < itemIndex + 8; i++) {
                        if (i < idropItems.length) {
                            if (idropItems[i].ObjectType == '2') {
                                var objectName = GetSubstring(idropItems[i].ObjectName.substring(0, idropItems[i].ObjectName.lastIndexOf('.')), 13);
                                var ext = idropItems[i].ObjectName.substring(idropItems[i].ObjectName.lastIndexOf('.') + 1).toLowerCase();
                                                             html += "<div class='ItemBox'>";
                                    html += "<object classid='" + clsid + "' width='101' height='101' >";
                                    html += "<param name='background' value=''>";
                                    html += "<param name='proxyrect' value='0, 0, 101, 101'>";
                                    html += "<param name='griprect' value='0, 0, 101, 101'>";
                                    html += "<param name='package'  value='GetIDropItem.aspx?guid=" + idropItems[i].ObjectId + "&type=xml'>";
                                    html += "<param name='validate' value='1'>";
                                    html += "<img src='GetIDropItemguid=" + idropItems[i].ObjectId + ".img' title= />";
                                    html += "</object>";
                                    html += "<span class='ItemName'>" + objectName + "</span>";
                                    html += "</div>";                                      
     
                            }
                        }
                    }
                    $("#c_" + pageIndex).html(html).attr("loaded", "1");
                }
                $("#c_" + pageIndex).show();
                currentDivIndex = pageIndex;
            }
     
    2.在silverlight4里面,可以在oob模式下可以直接调com组件,如下面代码段:就是通过AutomationFactory调用dt930的com组件
          if (Application.Current.InstallState != InstallState.Installed)
              Application.Current.Install();
     
          //oob模式,需要提升权限
          if (Application.Current.HasElevatedPermissions && System.Windows.Interop.ComAutomationFactory.IsAvailable)
           {
     
              ///AutomationFactory call com componnnet           
                dynamic dt = AutomationFactory.CreateObject("DT390COM.DT390");
     
          }
    需引用下面的命名空间
     
    using System.Dynamic;
     
    using System.Windows.Interop;
    using System.Runtime.InteropServices.Automation;
     
    3.上面2种方法都要求调用的外部程序是com组件,如果不是com组件,又该如何去启动外部程序呢.通过使用WScript.Shell 组件可以打开任何的应用程序
     
      eg  using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
             {
                    shell.Run(@"C:\windows\notepad.exe"); //you can open anything
                   shell.SendKeys(txtTextToSend.Text);
                   
              }
     
      除此之外还可以在js中调用
     
          <javascript language="javascipt">{
     
           var shell = new ActiveXObject("WScript.shell");
     
           shell.Run(@"C:\windows\notepad.exe"); 
    
        }
    

      

  • 相关阅读:
    SQL Server 索引的自动维护 <第十三篇>
    SQL Server 索引的图形界面操作 <第十二篇>
    python处理时间戳
    今天又犯了Java/Scala里面substring的错误
    新浪系统工程师笔试--shell
    把DEDE的在线文本编辑器换成Kindeditor不显示问题
    C语言 EOF是什么?
    Windows Server 2012 R2超级虚拟化之七 远程桌面服务的增强
    C++数据结构之最小生成树
    python sqlite 查询表的字段名 列名
  • 原文地址:https://www.cnblogs.com/zhangxin1989/p/2831351.html
Copyright © 2020-2023  润新知