基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
/******************************
|
||||
* 说明:窗口管理类
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2017-08-16
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
namespace Lskj.Util
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 窗口管理类
|
||||
/// </summary>
|
||||
public sealed class FormHelper
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr FindWindow(string className, string frmText);
|
||||
[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
|
||||
public static extern int ShowWindow(IntPtr hwnd, int showWay);
|
||||
public static IntPtr frmHwnd;
|
||||
/// <summary>
|
||||
/// C#库标准调用模式
|
||||
/// </summary>
|
||||
/// <param name="DllFileName"></param>
|
||||
/// <param name="args"></param>
|
||||
public static IForm LoadDllForm(string DllFileName, string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("反射开始:" + DateTime.Now);
|
||||
DllFileName = DllFileName.Replace("\\r", "").Replace("\\t", "").Replace("\\n", "");
|
||||
DllFileName = DllFileName.Equals("Lskj.PubAccraditationBrp.dll") ? "Lskj.PubAccraditation.dll" : DllFileName;
|
||||
DllFileName = DllFileName.Equals("Lskj.PubBatchBrower.dll") ? "Lskj.PubBrower.dll" : DllFileName;
|
||||
DllFileName = DllFileName.Equals("Lskj.SweepCodeSearch.dll") ? "Lskj.SweepCode.dll" : DllFileName;
|
||||
DllFileName = DllFileName.Equals("Lskj.PubModuleDetailSearch.dll") ? "Lskj.PubModuleDetail.dll" : DllFileName.Equals("Lskj.PubModuleSearch.dll") ? "Lskj.PubModule.dll" : DllFileName.Equals("Lskj.PubModuleDetailSearch3.dll") ? "Lskj.PubModuleDetail3.dll" : DllFileName;
|
||||
if (Lskj.Model.ERPInfo.Instance.PrimitiveBrowser && (DllFileName.Equals("Lskj.PubBrower.dll", StringComparison.CurrentCultureIgnoreCase) || DllFileName.Equals("Lskj.PubBrower2.dll", StringComparison.CurrentCultureIgnoreCase)))
|
||||
{
|
||||
DllFileName = "Lskj.PubBrowerXp.dll";
|
||||
}
|
||||
string libPath = DllFileName.Trim().ToLower().Equals("lskj.pubbrowser.dll") ? PubUtil.AbsolutelyBrowserPath + DllFileName : PubUtil.AbsolutelyLibPath + DllFileName;
|
||||
|
||||
Assembly _Assembly = Assembly.UnsafeLoadFrom(libPath);
|
||||
Type[] _types = _Assembly.GetTypes();
|
||||
foreach (Type _type in _types)
|
||||
{
|
||||
if (!_type.ToString().EndsWith(".DllBaseClass"))
|
||||
continue;
|
||||
object[] ol = new object[] { args };
|
||||
|
||||
Console.WriteLine("反射完成:" + DateTime.Now);
|
||||
//根据类型创建一个类并将参数通过构造函数传入
|
||||
return Activator.CreateInstance(_type, ol) as IForm;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Instance.WriteError(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:C#打开exe程序</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-16 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
public static void StartProcess(string exeName, string[] args = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process[] myprocess = Process.GetProcessesByName(exeName);
|
||||
if (myprocess.Count() == 0)//判断如果存在
|
||||
{
|
||||
if (args == null) args = new string[] { };
|
||||
string arg = string.Empty;
|
||||
foreach (string s in args)
|
||||
{
|
||||
arg += s + " ";
|
||||
}
|
||||
Process myproces = new Process();
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo(exeName + ".exe", arg.Trim());
|
||||
myproces.StartInfo = startInfo;
|
||||
myproces.StartInfo.UseShellExecute = false;
|
||||
myproces.Start();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Instance.WriteError(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user