111,126
社区成员
发帖
与我相关
我的任务
分享static class Program
{
private static frmMain _mainForm = null;
private static frmStartup _startForm = null;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
_startForm = new frmStartup();
_startForm.Show();
_mainForm = new frmMain();
_mainForm.Loaded += new EventHandler(_mainForm_Loaded);
Application.Run(_mainForm);
}
static void _mainForm_Loaded(object sender, EventArgs e)
{
_startForm.Close();
_startForm = null;
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
if (_startForm != null)
_startForm.Close();
_mainForm.Hook.ShowProcess("Ready", false);
AppLog.LogError(e.Exception.ToString());
MessageBox.Show(e.Exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public class SceneMgr
{
public static event EventHandler LoadComplete;
private SceneMgr()
{
LoadSceneFiles();
}
/// <summary>
/// 获取场景管理器单例
/// </summary>
/// <returns></returns>
public static SceneMgr GetSceneMgr()
{
if (_sm == null)
{
Mutex mu = new Mutex();
mu.WaitOne();
if (_sm == null)
{
_sm = new SceneMgr();
}
if (LoadComplete != null)
{
LoadComplete(null, null);
}
mu.Close();
}
return _sm;
}
}
public partial class LoadForm : Form
{
private void LoadSource()
{
SceneMgr.LoadComplete += new EventHandler(SceneMgr_LoadOk);
lblStatus.Text = "开始加载技能资源";
Application.DoEvents();
SceneMgr.GetSceneMgr();
}
}
void SceneMgr_LoadOk(object sender, EventArgs e)
{
lblStatus.Text = "资源加载已完成";
lblStatus.ForeColor = Color.Green;
Application.DoEvents();
Thread.Sleep(100);
this.Hide();
frm.Show();
}
public partial class LoadForm : Form
{
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x01;
private const int HTCAPTION = 0x02;
private FrmTestTool frm;
public LoadForm()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if ((int)m.Result == HTCLIENT)
{
m.Result = (IntPtr)HTCAPTION;
}
return;
}
base.WndProc(ref m);
}
private void LoadSource()
{
var dt = new DirectoryInfo("../Scene");
var max = dt.GetFiles().Where(f => !f.Name.Contains("S")).Count();
progressBar1.Maximum = max;
SceneMgr.LoadScene += new EventHandler<jy.DataEventArgs<string>>(SceneMgr_LoadScene);
SceneMgr.Increment += new EventHandler(SceneMgr_Increment);
SceneMgr.LoadComplete += new EventHandler(SceneMgr_LoadOk);
lblStatus.Text = "开始加载技能资源";
Application.DoEvents();
SkillMgr.GetSkillMgr();
SceneMgr.GetSceneMgr();
}
void SceneMgr_LoadOk(object sender, EventArgs e)
{
lblStatus.Text = "资源加载已完成";
lblStatus.ForeColor = Color.Green;
Application.DoEvents();
Thread.Sleep(100);
this.Hide();
frm.Show();
}
void SceneMgr_Increment(object sender, EventArgs e)
{
progressBar1.Increment(1);
}
void SceneMgr_LoadScene(object sender, jy.DataEventArgs<string> e)
{
lblStatus.Text = "正在加载资源" + e.Arg1; Application.DoEvents();
}
private void LoadForm_Shown(object sender, EventArgs e)
{
frm = new FrmTestTool();
LoadSource();
}
private void label1_Click(object sender, EventArgs e)
{
Application.Exit();
}