现在的位置: 首页 > 综合 > 正文

Wuyin.ShoesManager.Start 程序源代码(包括只启动一个实例及使用XP控件技术)

2012年10月31日 ⁄ 综合 ⁄ 共 2363字 ⁄ 字号 评论关闭

using System;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;

namespace Wuyin.ShoesManager
{
 ///

 /// Start 的摘要说明。
 ///

 public class Start
 {
  static FlashScreen fs = null;
  static string[] commandLineArgs = null;
  static bool isTest = false;
  static bool isXp = false;

  public static bool IsInXp
  {
   get
   {
    return isXp;
   }
  }

   public static FlashScreen flashScreen
  {
   get
   {
    return fs;
   }
  }

  public static string[] CommandLineArgs
  {
   get
   {
    return commandLineArgs;
   }
  }

  public Start()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }

  private static void ShowFocusWindow(int hwnd)
  {
   CommonClass.ShowWindow(hwnd,CommonClass.nCmdShow.SW_SHOW);
   CommonClass.SetForegroundWindow(hwnd);
  }

  [STAThread]
  public static void Main(string[] args)
  {
   bool noLogo = false;
   commandLineArgs = args;

   int hwnd = CommonClass.FindWindow(null,"无垠鞋业管理系统 - 登录");
   if(hwnd>0)
   {
    ShowFocusWindow(hwnd);
    return;
   }

   Process[] Procs = Process.GetProcesses();
   foreach(Process P in Procs)
   {
    string title = P.MainWindowTitle;
    if(title.StartsWith("无垠鞋业管理系统"))
    {
     hwnd = CommonClass.FindWindow(null,P.MainWindowTitle);
     ShowFocusWindow(hwnd);
     return;
    }
   }

   //如果在XP下则使用CommonControl 6 控件
   if(Environment.OSVersion.Version.Major > 4 & Environment.OSVersion.Version.Minor > 0 )
   {
    isXp = true;  
    if(!File.Exists(Application.ExecutablePath + ".manifest"))
    {
     StreamWriter sr = new StreamWriter(Application.ExecutablePath + ".manifest");
     sr.Write("\n\n\n.NET control deployment tool\n\n   \n     \n   \n\n");
     sr.Close();
     
     System.Diagnostics.Process P = System.Diagnostics.Process.Start(Application.ExecutablePath);
     
     Application.ExitThread();
     Application.Exit();
     return;
    }
   }

   foreach(string arg in args)
   {
    if(arg.ToUpper().EndsWith("NOLOGO"))
    {
     noLogo = true;
    }
    if(arg.ToUpper().EndsWith("/TEST"))
     isTest=true;
   }

   //显示SplashForm
   if(!noLogo)
   {
    fs = new FlashScreen();
    fs.Show();
   }

   //登录
   Wuyin.ShoesManager.frmLogin frm=new frmLogin();
   CommonClass.RecursivelyFormatForWinXP(frm);
   DialogResult result = frm.ShowDialog();
   if(result!=DialogResult.Yes)
   {
    frm.Close();
    if(fs!=null)
     fs.Close();
    Application.Exit();
   }
   else
   {
    frm.Close();
    StartMainForm();
   }
  }

  private static void StartMainForm()
  {
   fs.HideForm();
   if(!isTest)
    Application.Run(main.GetMainWindow);
   else
    Application.Run(new Form1());
  }
 }
}

抱歉!评论已关闭.