zoukankan      html  css  js  c++  java
  • 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"); 
    
        }
    

      

  • 相关阅读:
    iOS开发之UIWebView自动滑动到顶部-备
    Android开发者须知的几种APP加密方式--备
    UITableView 小节-备
    判断字符串是否为数字-备
    关于iOS上的对象映射公用方法-备
    嵌入式开发之项目---uboot 内存合集
    多媒体开发之---h.264 SPS PPS解析源代码,C实现一以及nal分析器
    YUV视频格式到RGB32格式转换的速度优化 上篇
    多媒体开发之---音视频解码 视频回调的空转陷阱
    收集的网络上大型的开源图像处理软件代码(提供下载链接)
  • 原文地址:https://www.cnblogs.com/zhangxin1989/p/2831351.html
Copyright © 2011-2022 走看看