From 20ab5384c87a6b9ee00ffe355d4be0c94db32ed5 Mon Sep 17 00:00:00 2001 From: Taiizor Date: Sun, 11 Apr 2021 22:50:10 +0300 Subject: [PATCH] 53X Again 8! --- src/Taskbar/Enum/Enums.cs | 2 +- src/Taskbar/Taskbar.cs | 164 +++++++++++++++++++++++++++++--- src/Taskbar/Value/Values.cs | 10 ++ src/Taskbar_CR/Main.Designer.cs | 32 ++++++- src/Taskbar_CR/Main.cs | 37 +++++-- src/Taskbar_CR/Main.resx | 33 +++++++ 6 files changed, 254 insertions(+), 24 deletions(-) diff --git a/src/Taskbar/Enum/Enums.cs b/src/Taskbar/Enum/Enums.cs index 735695b..514c9db 100644 --- a/src/Taskbar/Enum/Enums.cs +++ b/src/Taskbar/Enum/Enums.cs @@ -53,7 +53,7 @@ public enum EdgeType : uint /// /// /// - Bottom = 3 + Bot = 3 } /// diff --git a/src/Taskbar/Taskbar.cs b/src/Taskbar/Taskbar.cs index 6549bf5..3e63cba 100644 --- a/src/Taskbar/Taskbar.cs +++ b/src/Taskbar/Taskbar.cs @@ -95,18 +95,17 @@ public static Enums.LocationType SingleDetect /// /// /// - public static Dictionary MultiDetectDictionary + public static List MultiDetectList { get { try { - Dictionary Result = new(); - int Count = 0; + List Result = new(); foreach (Screen Screen in Screen.AllScreens) { - Result.Add(Count++, Detect(Screen)); + Result.Add(Detect(Screen)); } return Result; @@ -121,17 +120,18 @@ public static Enums.LocationType SingleDetect /// /// /// - public static List MultiDetectList + public static Dictionary MultiDetectDictionary { get { try { - List Result = new(); + Dictionary Result = new(); + int Count = 0; foreach (Screen Screen in Screen.AllScreens) { - Result.Add(Detect(Screen)); + Result.Add(Count++, Detect(Screen)); } return Result; @@ -263,7 +263,7 @@ public static Rectangle DisplayBounds { try { - if (RefreshBoundsAndPosition()) + if (RefreshBoundsAndPosition) { return Rectangle.FromLTRB(Values.BarData.Rect.Left, Values.BarData.Rect.Top, Values.BarData.Rect.Right, Values.BarData.Rect.Bot); } @@ -304,7 +304,7 @@ public static Enums.LocationType Position { try { - if (RefreshBoundsAndPosition()) + if (RefreshBoundsAndPosition) { return (Enums.LocationType)Values.BarData.uEdge; } @@ -353,19 +353,159 @@ public static void Show() /// /// /// + /// /// - private static bool RefreshBoundsAndPosition() + public static Rectangle FindDockedTaskbar(Screen Screen) { try { - //! SHAppBarMessage returns IntPtr.Zero **if it fails** - return SHAppBarMessage(Enums.MessageType.GetTaskbarPos, ref Values.BarData) != IntPtr.Zero; + Rectangle Rect = new(); + + int LeftDockedWidth = Math.Abs(Math.Abs(Screen.Bounds.Left) - Math.Abs(Screen.WorkingArea.Left)); + int TopDockedHeight = Math.Abs(Math.Abs(Screen.Bounds.Top) - Math.Abs(Screen.WorkingArea.Top)); + int RightDockedWidth = Screen.Bounds.Width - LeftDockedWidth - Screen.WorkingArea.Width; + int BotDockedHeight = Screen.Bounds.Height - TopDockedHeight - Screen.WorkingArea.Height; + + if (LeftDockedWidth > 0) + { + Rect.X = Screen.Bounds.Left; + Rect.Y = Screen.Bounds.Top; + Rect.Width = LeftDockedWidth; + Rect.Height = Screen.Bounds.Height; + } + else if (RightDockedWidth > 0) + { + Rect.X = Screen.WorkingArea.Right; + Rect.Y = Screen.Bounds.Top; + Rect.Width = RightDockedWidth; + Rect.Height = Screen.Bounds.Height; + } + else if (TopDockedHeight > 0) + { + Rect.X = Screen.WorkingArea.Left; + Rect.Y = Screen.Bounds.Top; + Rect.Width = Screen.WorkingArea.Width; + Rect.Height = TopDockedHeight; + } + else if (BotDockedHeight > 0) + { + Rect.X = Screen.WorkingArea.Left; + Rect.Y = Screen.WorkingArea.Bottom; + Rect.Width = Screen.WorkingArea.Width; + Rect.Height = BotDockedHeight; + } + else + { + //throw new Exception(Values.Nothing); + + Rect.X = Screen.WorkingArea.Left; + Rect.Y = Screen.WorkingArea.Top; + Rect.Width = Screen.WorkingArea.Width; + Rect.Height = Screen.WorkingArea.Height; + } + + return Rect; } catch { throw new Exception(Values.Exception); } } + + /// + /// + /// + /// + public static List FindDockedTaskbarsList + { + get + { + try + { + List DockedRects = new(); + + foreach (Screen Screen in Screen.AllScreens) + { + /* + if (!Screen.Bounds.Equals(Screen.WorkingArea)) + { + DockedRects.Add(FindDockedTaskbar(Screen)); + } + */ + DockedRects.Add(FindDockedTaskbar(Screen)); + } + + if (DockedRects.Count == 0) + { + //throw new Exception(Values.AutoHide); + } + + return DockedRects; + } + catch + { + throw new Exception(Values.Exception); + } + } + } + + /// + /// + /// + /// + public static Dictionary FindDockedTaskbarsDictionary + { + get + { + try + { + Dictionary DockedRects = new(); + int Count = 0; + + foreach (Screen Screen in Screen.AllScreens) + { + /* + if (!Screen.Bounds.Equals(Screen.WorkingArea)) + { + DockedRects.Add(Count++, FindDockedTaskbar(Screen)); + } + */ + DockedRects.Add(Count++, FindDockedTaskbar(Screen)); + } + + if (DockedRects.Count == 0) + { + //throw new Exception(Values.AutoHide); + } + + return DockedRects; + } + catch + { + throw new Exception(Values.Exception); + } + } + } + + /// + /// + /// + /// + private static bool RefreshBoundsAndPosition + { + get + { + try + { + //! SHAppBarMessage returns IntPtr.Zero **if it fails** + return SHAppBarMessage(Enums.MessageType.GetTaskbarPos, ref Values.BarData) != IntPtr.Zero; + } + catch + { + throw new Exception(Values.Exception); + } + } + } } #endregion } diff --git a/src/Taskbar/Value/Values.cs b/src/Taskbar/Value/Values.cs index e64bbf5..49d1665 100644 --- a/src/Taskbar/Value/Values.cs +++ b/src/Taskbar/Value/Values.cs @@ -17,6 +17,16 @@ public class Values /// public const string Exception = "An unexpected error occurred."; + /// + /// + /// + public const string AutoHide = "The taskbar is set to auto hide."; + + /// + /// + /// + public const string Nothing = "Nothing was found."; + /// /// /// diff --git a/src/Taskbar_CR/Main.Designer.cs b/src/Taskbar_CR/Main.Designer.cs index 2ece3b0..1367f92 100644 --- a/src/Taskbar_CR/Main.Designer.cs +++ b/src/Taskbar_CR/Main.Designer.cs @@ -37,6 +37,8 @@ private void InitializeComponent() this.button6 = new System.Windows.Forms.Button(); this.button7 = new System.Windows.Forms.Button(); this.button8 = new System.Windows.Forms.Button(); + this.button9 = new System.Windows.Forms.Button(); + this.button10 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 @@ -51,7 +53,7 @@ private void InitializeComponent() // // button2 // - this.button2.Location = new System.Drawing.Point(168, 12); + this.button2.Location = new System.Drawing.Point(324, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(150, 64); this.button2.TabIndex = 1; @@ -111,7 +113,7 @@ private void InitializeComponent() // // button8 // - this.button8.Location = new System.Drawing.Point(324, 12); + this.button8.Location = new System.Drawing.Point(168, 12); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(150, 64); this.button8.TabIndex = 7; @@ -119,11 +121,33 @@ private void InitializeComponent() this.button8.UseVisualStyleBackColor = true; this.button8.Click += new System.EventHandler(this.Button8_Click); // + // button9 + // + this.button9.Location = new System.Drawing.Point(324, 166); + this.button9.Name = "button9"; + this.button9.Size = new System.Drawing.Size(150, 64); + this.button9.TabIndex = 8; + this.button9.Text = "Advanced\r\nFind Docked Taskbars List"; + this.button9.UseVisualStyleBackColor = true; + this.button9.Click += new System.EventHandler(this.Button9_Click); + // + // button10 + // + this.button10.Location = new System.Drawing.Point(12, 236); + this.button10.Name = "button10"; + this.button10.Size = new System.Drawing.Size(150, 64); + this.button10.TabIndex = 9; + this.button10.Text = "Advanced\r\nFind Docked Taskbars Dictionary"; + this.button10.UseVisualStyleBackColor = true; + this.button10.Click += new System.EventHandler(this.Button10_Click); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.ClientSize = new System.Drawing.Size(486, 241); + this.ClientSize = new System.Drawing.Size(486, 312); + this.Controls.Add(this.button10); + this.Controls.Add(this.button9); this.Controls.Add(this.button8); this.Controls.Add(this.button7); this.Controls.Add(this.button6); @@ -154,5 +178,7 @@ private void InitializeComponent() private System.Windows.Forms.Button button6; private System.Windows.Forms.Button button7; private System.Windows.Forms.Button button8; + private System.Windows.Forms.Button button9; + private System.Windows.Forms.Button button10; } } \ No newline at end of file diff --git a/src/Taskbar_CR/Main.cs b/src/Taskbar_CR/Main.cs index e3c45ca..f4833b1 100644 --- a/src/Taskbar_CR/Main.cs +++ b/src/Taskbar_CR/Main.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Windows.Forms; using Taskbar.Enum; using static Taskbar.Taskbar; @@ -18,23 +19,23 @@ private void Button1_Click(object sender, EventArgs e) MessageBox.Show(Simple.SingleDetect.ToString()); } - private void Button2_Click(object sender, EventArgs e) + private void Button8_Click(object sender, EventArgs e) { - Dictionary Screen = Simple.MultiDetectDictionary; + List Screen = Simple.MultiDetectList; - foreach (KeyValuePair Var in Screen) + foreach (Enums.LocationType Var in Screen) { - MessageBox.Show(Var.Key + ": " + Var.Value); + MessageBox.Show(Var.ToString()); } } - private void Button8_Click(object sender, EventArgs e) + private void Button2_Click(object sender, EventArgs e) { - List Screen = Simple.MultiDetectList; + Dictionary Screen = Simple.MultiDetectDictionary; - foreach (Enums.LocationType Var in Screen) + foreach (KeyValuePair Var in Screen) { - MessageBox.Show(Var.ToString()); + MessageBox.Show("Screen " + Var.Key + " => " + Var.Value); } } @@ -62,5 +63,25 @@ private void Button7_Click(object sender, EventArgs e) { Advanced.Show(); } + + private void Button9_Click(object sender, EventArgs e) + { + List Rectangle = Advanced.FindDockedTaskbarsList; + + foreach (Rectangle Var in Rectangle) + { + MessageBox.Show("X: " + Var.X + "\nY: " + Var.Y + "\nWidth: " + Var.Width + "\nHeight: " + Var.Height); + } + } + + private void Button10_Click(object sender, EventArgs e) + { + Dictionary Rectangle = Advanced.FindDockedTaskbarsDictionary; + + foreach (KeyValuePair Var in Rectangle) + { + MessageBox.Show("Screen " + Var.Key + " =>\n" + "\tX: " + Var.Value.X + "\n\tY: " + Var.Value.Y + "\n\tWidth: " + Var.Value.Width + "\n\tHeight: " + Var.Value.Height); + } + } } } \ No newline at end of file diff --git a/src/Taskbar_CR/Main.resx b/src/Taskbar_CR/Main.resx index af2ed69..90b8ec8 100644 --- a/src/Taskbar_CR/Main.resx +++ b/src/Taskbar_CR/Main.resx @@ -117,6 +117,39 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True +