From 3b35535aa9d822ef105350bd69a350f67feec5ae Mon Sep 17 00:00:00 2001 From: DWAK-ATTK Date: Sat, 4 Jul 2020 11:44:31 -0700 Subject: [PATCH] removed from Alt-Tab list --- WindowMoniker/App.config | 13 +++--- WindowMoniker/Form1.Designer.cs | 1 + WindowMoniker/Form1.cs | 80 ++++++++++++++++++++++++++------- WindowMoniker/Options.cs | 3 ++ 4 files changed, 75 insertions(+), 22 deletions(-) diff --git a/WindowMoniker/App.config b/WindowMoniker/App.config index 69b4ed9..f06b1b8 100644 --- a/WindowMoniker/App.config +++ b/WindowMoniker/App.config @@ -3,7 +3,7 @@ - + @@ -12,13 +12,12 @@ + + + + + - - - - - - diff --git a/WindowMoniker/Form1.Designer.cs b/WindowMoniker/Form1.Designer.cs index a874c9a..ba16532 100644 --- a/WindowMoniker/Form1.Designer.cs +++ b/WindowMoniker/Form1.Designer.cs @@ -50,6 +50,7 @@ private void InitializeComponent() { this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(2699, 995); + this.ControlBox = false; this.Controls.Add(this.panel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "Form1"; diff --git a/WindowMoniker/Form1.cs b/WindowMoniker/Form1.cs index ae07dcd..9d48d0f 100644 --- a/WindowMoniker/Form1.cs +++ b/WindowMoniker/Form1.cs @@ -29,12 +29,19 @@ public Form1() { #if !DEBUG this.TopMost = true; +#endif + } + + - // Remove window from Alt-Tab - int exStyle = (int)GetWindowLong(this.Handle, (int)GetWindowLongFields.GWL_EXSTYLE); - exStyle |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW; - SetWindowLong(this.Handle, (int)GetWindowLongFields.GWL_EXSTYLE, (IntPtr)exStyle); + protected override CreateParams CreateParams { + get { + var Params = base.CreateParams; +#if !DEBUG + Params.ExStyle |= 0x80; #endif + return Params; + } } @@ -155,16 +162,28 @@ private void DrawRightDiagonal(Graphics g) { private void DrawDashed(Graphics g) { - int x = -20; - int y = 0; - int buffer = _options.Buffers.Left; + Buffers positions = new Buffers(0, 0, 0, 0); + BufferPens pens = new BufferPens(_options.Buffers * 3, _options.ForeColor); int maxIndex = Math.Max(this.Width, this.Height); - for (int index = buffer; index < maxIndex; index += buffer * 3) { - y += buffer * 5; + while (positions.Left < maxIndex) { + positions += _options.Buffers * 6; + + // Left/Right edge: only draw when below the top border and above the bottom border. + if (_options.Buffers.Top <= positions.Left && positions.Left <= (this.Height - (_options.Buffers.Bottom * 2))) { + g.DrawLine(pens.Left, 0, positions.Left, _options.Buffers.Left, positions.Left); // Left + } + if (_options.Buffers.Top <= positions.Right && positions.Right <= (this.Height - (_options.Buffers.Bottom * 2))) { + g.DrawLine(pens.Right, this.Width - _options.Buffers.Right, positions.Right, this.Width, positions.Right); // Right + } + + if (_options.Buffers.Left <= positions.Top && positions.Top <= (this.Width - (_options.Buffers.Right * 2))) { + g.DrawLine(pens.Top, positions.Top, 0, positions.Top, _options.Buffers.Top); + } + if (_options.Buffers.Left <= positions.Bottom && positions.Bottom <= (this.Width - (_options.Buffers.Right * 2))) { + g.DrawLine(pens.Bottom, positions.Bottom, this.Height - _options.Buffers.Bottom, positions.Bottom, this.Height); + } - g.DrawLine(_options.ForePen, x, y, this.Width + 20, y); - g.DrawLine(_options.ForePen, y, -20, y, this.Height + 20); } } @@ -187,8 +206,12 @@ private void DrawDotted(Graphics g) { g.DrawLine(pens.Right, this.Width - _options.Buffers.Right, positions.Right, this.Width, positions.Right); // Right } - g.DrawLine(pens.Top, positions.Top, 0, positions.Top, _options.Buffers.Top); - g.DrawLine(pens.Bottom, positions.Bottom, this.Height - _options.Buffers.Bottom, positions.Bottom, this.Height); + if (_options.Buffers.Left <= positions.Top && positions.Top <= (this.Width - (_options.Buffers.Right * 2))) { + g.DrawLine(pens.Top, positions.Top, 0, positions.Top, _options.Buffers.Top); + } + if (_options.Buffers.Left <= positions.Bottom && positions.Bottom <= (this.Width - (_options.Buffers.Right * 2))) { + g.DrawLine(pens.Bottom, positions.Bottom, this.Height - _options.Buffers.Bottom, positions.Bottom, this.Height); + } } } @@ -196,7 +219,34 @@ private void DrawDotted(Graphics g) { private void DrawTitle(Graphics g) { + if (string.IsNullOrWhiteSpace(_options.Title)) { return; } + + Size titleSize = GetTitleSize(g); + Rectangle rectangle = new Rectangle( + (this.Width / 2) - (titleSize.Width / 2)-20, 0, + titleSize.Width+40, _options.Buffers.Top); + g.FillRectangle(_options.TitleBackBrush, rectangle); + g.DrawString(_options.Title, _options.TitleFont, _options.TitleForeBrush, rectangle.X+20, -3); + } + + + private Size GetTitleSize(Graphics g) { + Size result = new Size(); + + StringFormat stringFormat = new StringFormat(); ; + stringFormat.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, _options.Title.Length) }); + + Region[] regions = + g.MeasureCharacterRanges(_options.Title, _options.TitleFont, + new RectangleF(0, 0, this.Width, this.Height), stringFormat); + + foreach (Region region in regions) { + result.Width += (int)region.GetBounds(g).Width; + } + result.Height = (int)regions[0].GetBounds(g).Height; + + return result; } @@ -205,7 +255,7 @@ private void DrawTitle(Graphics g) { - #region Window styles +#region Window styles [Flags] public enum ExtendedWindowStyles { // ... @@ -258,7 +308,7 @@ private static int IntPtrToInt32(IntPtr intPtr) { [DllImport("kernel32.dll", EntryPoint = "SetLastError")] public static extern void SetLastError(int dwErrorCode); - #endregion +#endregion diff --git a/WindowMoniker/Options.cs b/WindowMoniker/Options.cs index f2e67ed..795471f 100644 --- a/WindowMoniker/Options.cs +++ b/WindowMoniker/Options.cs @@ -47,6 +47,7 @@ public Options() { if (!string.IsNullOrWhiteSpace(value)) { TitleFontSize = float.Parse(value); } + TitleFont= new Font("Arial", TitleFontSize, FontStyle.Regular); value = ConfigurationManager.AppSettings["TitleForeColor"]; if (!string.IsNullOrWhiteSpace(value)) { @@ -114,6 +115,8 @@ public Pen BackPen { public float TitleFontSize { get; set; } = 8.0f; + public Font TitleFont { get; set; } = new Font("Arial", 8.0f, FontStyle.Regular); + public Color TitleForeColor { get; set; } = Color.White; public Color TitleBackColor { get; set; } = Color.Black;