涉及类:
1、 启动画面类:
public class SplashForm : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lbl_version;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public SplashForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
lbl_version.Text = "版本:" + Application.ProductVersion;
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
//以下省略
2、 应用程序加载类:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Reflection;
using System.IO;
namespace Heroic.TempAnalyse.TempGui
{
/// <summary>
/// AppLoader 的摘要说明。
/// </summary>
public class AppLoader
{
private static ApplicationContext context;
private static SplashForm sForm = new SplashForm();
private static MainWindow mForm = null;
//0不可见但仍然运行,1居中,2最小化,3最大化
private const int WS_SHOWNORMAL = 3;
[STAThread]
static void Main(string[] args)
{
// [8/12/2004]用于更新该程序。
doUpData();
// [7/19/2004] 改变顺序,目的使得开始加载速度加快
//得到正在运行的例程
Process instance = RunningInstance();
if(instance == null)
{
sForm.Show();
mForm = new MainWindow();
context = new ApplicationContext();
Application.Idle += new EventHandler(OnAppIdle);
Application.Run(context);
}
else
{
//处理发现的例程
HandleRunningInstance(instance);
//MessageBox.Show("当前程序已经运行了!");
}
}
//在线更新用,不再本文范围
private static void doUpData()
{
System.Diagnostics.Process.Start(Application.StartupPath+@"\update.exe",Application.StartupPath+@"\Heroic.TempAnalyse.TempGui.exe 0");//
}
private static void OnAppIdle(object sender, EventArgs e)
{
if(context.MainForm == null)
{
Application.Idle -= new EventHandler(OnAppIdle);
mForm.PreLoad();
context.MainForm = mForm;
context.MainForm.Show();
sForm.Close();
sForm = null;
}
}
//不允许有两个程序同时启动
public static Process RunningInstance()
{
Process current