using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; namespace SuperMap.RealEstate.Launcher.Loading { internal partial class frmProgress : Form { const int hWnd_User_Defined = 0x500; const int hWnd_ProcessText = hWnd_User_Defined + 11; const int hWnd_Progress1Visible = hWnd_User_Defined + 20; const int hWnd_Progress1Value = hWnd_User_Defined + 21; const int hWnd_Progress2Visible = hWnd_User_Defined + 30; const int hWnd_Progress2Value = hWnd_User_Defined + 31; const int hWnd_Progress2Maximum = hWnd_User_Defined + 32; const int hWnd_Form_Abort = hWnd_User_Defined + 90; const int hWnd_Form_Closing = hWnd_User_Defined + 91; const int hWnd_Form_ForceExit = hWnd_User_Defined + 92; const int hWnd_MessageLoad = hWnd_User_Defined + 101; const int hWnd_MessageSave = hWnd_User_Defined + 102; [DllImport("User32.DLL")] static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); [DllImport("User32.DLL")] static extern bool ReleaseCapture(); const uint WM_SYSCOMMAND = 0x0112; const int SC_MOVE = 61456; const int HTCAPTION = 2; public frmProgress() { InitializeComponent(); } protected override void DefWndProc(ref Message m) { switch (m.Msg) { case hWnd_MessageLoad: string _FileLoadNumber = m.LParam.ToInt32().ToString(); string _LoadMessagePath = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + "..\\Temp\\Message\\"); _LoadMessagePath += _FileLoadNumber + ".txt"; if (File.Exists(_LoadMessagePath)) { string _lineText; List _LineList = new List(); using (StreamReader _FileText = File.OpenText(_LoadMessagePath)) { while (!_FileText.EndOfStream) { _lineText = _FileText.ReadLine(); ProgressBarText = _lineText; _LineList.Add(_lineText); } richTextBox1.Text = string.Join("\r\n", _LineList.ToArray()); _FileText.Close(); } File.Delete(_LoadMessagePath); } break; case hWnd_MessageSave: string _FileSaveNumber = m.LParam.ToInt32().ToString(); string _SaveMessagePath = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + "..\\Temp\\Message\\"); _SaveMessagePath += _FileSaveNumber + ".txt"; if (File.Exists(_SaveMessagePath)) File.Delete(_SaveMessagePath); using (StreamWriter _FileText = File.AppendText(_SaveMessagePath)) { _FileText.Write(richTextBox1.Text); _FileText.Close(); } ProgressBarText = "更新 当前组件..."; Application.DoEvents(); Thread.Sleep(200); ProgressBarText = "3秒后自动关闭..."; Application.DoEvents(); Thread.Sleep(3000); break; case hWnd_ProcessText: _EnabledClosed(); string _FileNumber = m.LParam.ToInt32().ToString(); string _MessagePath = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + "..\\Temp\\Message\\"); _MessagePath += _FileNumber + ".txt"; if (File.Exists(_MessagePath)) { using (StreamReader _FileText = File.OpenText(_MessagePath)) { ProgressBarText = _FileText.ReadToEnd(); _FileText.Close(); File.Delete(_MessagePath); } } else ProgressBarText = "错误的参数" + _MessagePath; break; case hWnd_Progress1Value: _EnabledClosed(); SetProgressPercentage(progressBar1, m.LParam.ToInt32()); label3.Text = progressBar1.Value.ToString() + "%"; if (progressBar1.Value == progressBar1.Maximum) { if (progressBar2.Maximum == 0 || progressBar2.Value == progressBar2.Maximum) { progressBar1.Visible = false; label3.Visible = false; } } else { progressBar1.Visible = true; label3.Visible = true; } break; case hWnd_Progress2Value: _EnabledClosed(); SetProgressPercentage(progressBar2, m.LParam.ToInt32()); label2.Text = "第 " + (progressBar2.Value + 1).ToString() + " 共 " + progressBar2.Maximum + " 个"; if (progressBar2.Value == progressBar2.Maximum) { label2.Visible = false; if (progressBar1.Value == progressBar1.Maximum) { progressBar1.Visible = false; label3.Visible = false; } } else label2.Visible = true; break; case hWnd_Progress2Maximum: _EnabledClosed(); progressBar2.Value = 0; progressBar2.Maximum = m.LParam.ToInt32(); label2.Text = "第 " + (progressBar2.Value + 1).ToString() + " 共 " + progressBar2.Maximum + " 个"; if (progressBar2.Maximum > 0) label2.Visible = true; else label2.Visible = false; break; case hWnd_Form_ForceExit: //NewMethod(); //timer1.Interval = 1000; //timer1.Enabled = true; this.Close(); break; case hWnd_Form_Closing: _EnabledClosed(); int _Interval = m.LParam.ToInt32() * 1000; if (_Interval > 0) { timer1.Interval = _Interval; timer1.Enabled = true; } else this.Close(); break; default: base.DefWndProc(ref m); break; } } List _ProgressBarTextList = new List(); string _ProgressBarText; public string ProgressBarText { get { return _ProgressBarText; } set { string _value = value; if (!_value.StartsWith("「")) _value = "「" + DateTime.Now.ToLongTimeString() + "」" + _value; richTextBox1.AppendText("\r\n" + _value); if (_ProgressBarTextList.Count >= 5) _ProgressBarTextList.RemoveAt(0); _ProgressBarTextList.Add(_value); _ProgressBarText = string.Join("\r\n", _ProgressBarTextList.ToArray()); label1.Text = _ProgressBarText; } } void SetProgressPercentage(ProgressBar progressBar, int progressPercentage) { if (progressPercentage > progressBar.Maximum) progressBar.Value = progressBar.Maximum; else if (progressPercentage < progressBar.Minimum) progressBar.Value = progressBar.Minimum; else progressBar.Value = progressPercentage; } private void frmProgress_Load(object sender, EventArgs e) { int height = SystemInformation.WorkingArea.Height; int width = SystemInformation.WorkingArea.Width; int formheight = this.Height; int formwidth = this.Width; int newformx = width / 2 - formwidth / 2; int newformy = height / 5 - formheight / 5; this.SetDesktopLocation(newformx, newformy); label1.Text = ""; //ProgressBarText = "「" + DateTime.Now.ToLongTimeString() + "」系统 初始化.."; //richTextBox1.Text = ProgressBarText; richTextBox1.Text = "「" + DateTime.Now.ToLongTimeString() + "」系统 初始化..."; } private void progressBar1_VisibleChanged(object sender, EventArgs e) { } private void _EnabledClosed() { timer1.Enabled = false; //_CloseForm = 0; } bool _CloseForm = false; private void timer1_Tick(object sender, EventArgs e) { this.timer1.Enabled = false; //if (_CloseForm == false) this.Close(); } private void Form_MouseDown(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) _CloseForm = true; ReleaseCapture(); SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0); } void label4_MouseClick(object sender, MouseEventArgs e) { this.Close(); } private void label1_DoubleClick(object sender, EventArgs e) { richTextBox1.Visible = true; richTextBox1.Width = label1.Width; richTextBox1.Height = label1.Height; richTextBox1.Left = label1.Left; richTextBox1.Top = label1.Top; _CloseForm = true; } private void label1_MouseHover(object sender, EventArgs e) { toolTip1.Show("右键双击显示更多内容!", label1); } private void richTextBox1_DoubleClick(object sender, EventArgs e) { richTextBox1.Visible = false; } private void label6_Click(object sender, EventArgs e) { this.Close(); } private void label6_MouseMove(object sender, MouseEventArgs e) { //label6.ForeColor = Color.Red; } private void label6_MouseEnter(object sender, EventArgs e) { label6.BackColor = Color.Red; } private void label6_MouseLeave(object sender, EventArgs e) { label6.BackColor = Color.Transparent; } } }