星空网 > 软件开发 > ASP.net

web页面启动winform程序

1、页面html代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html "http://www.w3.org/1999/xhtml"> <head>   <title></title>   <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> </head>  <body>    <div>      <a href="OraAns://传入exe文件的参数">        打开1      </a>    <br>      <a href="OraAns://传入exe文件的参数">        打开2      </a>    <br>       <a href="OraAns://传入exe文件的参数">        打开3      </a>    <br>       <a href="OraAns://传入exe文件的参数">        打开4      </a>    <br>    </div>  </body></html>

2、页面启动的程序是通过注册表来启动的

xxx.reg操作注册表文件代码

Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\OraAns] "URL Protocol"="E:\\Debug\\xxx.exe" @="OralAnswerProtocol" [HKEY_CLASSES_ROOT\OraAns\DefaultIcon] @="E:\\Debug\\xxx.exe,1" [HKEY_CLASSES_ROOT\OraAns\shell] [HKEY_CLASSES_ROOT\OraAns\shell\open] [HKEY_CLASSES_ROOT\OraAns\shell\open\command] @="\"E:\\Debug\\xxx.exe\" \"%1\""

3、winform程序处理页面传入的参数(基于C#)

1)、Program.cs文件代码

using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;using System.Text.RegularExpressions;using Microsoft.Win32;using System.Threading;namespace OraAns{  static class Program  {    public static EventWaitHandle ProgramStarted; //事件等待句柄    /// <summary>    /// 应用程序的主入口点。    /// </summary>    [STAThread]    static void Main(string[] args)    {      if (args.Length > 0)  //从页面启动时有参数传入,否则直接启动      {        string sParameterValue = Regex.Match(args[0], "^[0-9a-zA-Z]+://(.+)$").Groups[1].Value;        FilterInvalidCharacter(ref sParameterValue);        Registry.SetValue(@"HKEY_CURRENT_USER\Software\OraAnsParameters", "", sParameterValue);  //将经过处理的传入参数写入注册表                bool bIsOrNotCreateNew;        ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "OraAnsClient", out bIsOrNotCreateNew);        if (!bIsOrNotCreateNew)        {          //winform程序已经启动时执行                    ProgramStarted.Set();          return;        }      }      Application.EnableVisualStyles();      Application.SetCompatibleTextRenderingDefault(false);      Application.Run(new OralAnswerMain());    }    /// <summary>    /// 处理页面传回的参数的非法字符    /// </summary>    /// <param name="sParameterValue"></param>    static void FilterInvalidCharacter(ref string sParameterValue)    {      int nStrLength = sParameterValue.Length;      if (nStrLength > 0)      {        if ('/' == sParameterValue[nStrLength - 1])        {          if (1 == nStrLength)          {            sParameterValue = "";          }          else          {            sParameterValue = sParameterValue.Substring(0, nStrLength - 1);          }        }      }    }  }}

2)、winform代码文件的代码

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using Microsoft.Win32;using System.Threading;namespace OraAns{  public partial class OraAnsMain : Form  {           /// <summary>    /// 构造函数    /// </summary>    public OraAnsMain()    {      InitializeComponent();      try      {        //从注册表中获取页面传递过来的参数并解析        object Obj = Registry.GetValue(@"HKEY_CURRENT_USER\Software\OraAnsParameters", "", string.Empty);        if (Obj != null)        {          string sReString = Obj as string;                    //TODO:解析从页面传入的字符串参数        }        if (Program.ProgramStarted != null)        {          ThreadPool.RegisterWaitForSingleObject(Program.ProgramStarted, OnProgramStarted, this, -1, false); //注册线程委托        }      }      catch (Exception e)      {        e.ToString();      }    }    
public delegate void MyInvoke(); //声明委托 //ThreadPool.RegisterWaitForSingleObject方法执行的回调 void OnProgramStarted(object state, bool timeout) { try { //通过委托进行异步调用的处理,避免不同线程操作UI线程 MyInvoke mi = new MyInvoke(UIinitial); this.BeginInvoke(mi, new Object[] { /*UIinitial方法调用的输入参数对象*/ }); } catch (Exception e) { e.ToString(); } } /// <summary> /// UI显示初始化 /// </summary> void UIinitial() { //TODO:UI初始化的处理 }
private void OraAnsMain_Load(object sender, EventArgs e) { } }}

 

......




原标题:web页面启动winform程序

关键词:web

web
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

天津到马来西亚船运:https://www.goluckyvip.com/tag/92496.html
上海到马来西亚运价:https://www.goluckyvip.com/tag/92497.html
马来西亚到宁波船运几天:https://www.goluckyvip.com/tag/92498.html
中国走吉隆坡海运:https://www.goluckyvip.com/tag/92499.html
土耳其统计局:https://www.goluckyvip.com/tag/925.html
出道即巅峰:https://www.goluckyvip.com/tag/9250.html
德国vat税号查询的网站是什么:https://www.kjdsnews.com/a/1842258.html
德国vat税号查询的网站是什么:https://www.xlkjsw.com/news/93310.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流