Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
53X Again 8!
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor authored and Taiizor committed Apr 11, 2021
1 parent 8cf2608 commit 20ab538
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Taskbar/Enum/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum EdgeType : uint
/// <summary>
///
/// </summary>
Bottom = 3
Bot = 3
}

/// <summary>
Expand Down
164 changes: 152 additions & 12 deletions src/Taskbar/Taskbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,17 @@ public static Enums.LocationType SingleDetect
/// <summary>
///
/// </summary>
public static Dictionary<int, Enums.LocationType> MultiDetectDictionary
public static List<Enums.LocationType> MultiDetectList
{
get
{
try
{
Dictionary<int, Enums.LocationType> Result = new();
int Count = 0;
List<Enums.LocationType> Result = new();

foreach (Screen Screen in Screen.AllScreens)
{
Result.Add(Count++, Detect(Screen));
Result.Add(Detect(Screen));
}

return Result;
Expand All @@ -121,17 +120,18 @@ public static Enums.LocationType SingleDetect
/// <summary>
///
/// </summary>
public static List<Enums.LocationType> MultiDetectList
public static Dictionary<int, Enums.LocationType> MultiDetectDictionary
{
get
{
try
{
List<Enums.LocationType> Result = new();
Dictionary<int, Enums.LocationType> Result = new();
int Count = 0;

foreach (Screen Screen in Screen.AllScreens)
{
Result.Add(Detect(Screen));
Result.Add(Count++, Detect(Screen));
}

return Result;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -304,7 +304,7 @@ public static Enums.LocationType Position
{
try
{
if (RefreshBoundsAndPosition())
if (RefreshBoundsAndPosition)
{
return (Enums.LocationType)Values.BarData.uEdge;
}
Expand Down Expand Up @@ -353,19 +353,159 @@ public static void Show()
/// <summary>
///
/// </summary>
/// <param name="Screen"></param>
/// <returns></returns>
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);
}
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public static List<Rectangle> FindDockedTaskbarsList
{
get
{
try
{
List<Rectangle> 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);
}
}
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public static Dictionary<int, Rectangle> FindDockedTaskbarsDictionary
{
get
{
try
{
Dictionary<int, Rectangle> 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);
}
}
}

/// <summary>
///
/// </summary>
/// <returns></returns>
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
}
Expand Down
10 changes: 10 additions & 0 deletions src/Taskbar/Value/Values.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public class Values
/// </summary>
public const string Exception = "An unexpected error occurred.";

/// <summary>
///
/// </summary>
public const string AutoHide = "The taskbar is set to auto hide.";

/// <summary>
///
/// </summary>
public const string Nothing = "Nothing was found.";

/// <summary>
///
/// </summary>
Expand Down
32 changes: 29 additions & 3 deletions src/Taskbar_CR/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 29 additions & 8 deletions src/Taskbar_CR/Main.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Taskbar.Enum;
using static Taskbar.Taskbar;
Expand All @@ -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<int, Enums.LocationType> Screen = Simple.MultiDetectDictionary;
List<Enums.LocationType> Screen = Simple.MultiDetectList;

foreach (KeyValuePair<int, Enums.LocationType> 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<Enums.LocationType> Screen = Simple.MultiDetectList;
Dictionary<int, Enums.LocationType> Screen = Simple.MultiDetectDictionary;

foreach (Enums.LocationType Var in Screen)
foreach (KeyValuePair<int, Enums.LocationType> Var in Screen)
{
MessageBox.Show(Var.ToString());
MessageBox.Show("Screen " + Var.Key + " => " + Var.Value);
}
}

Expand Down Expand Up @@ -62,5 +63,25 @@ private void Button7_Click(object sender, EventArgs e)
{
Advanced.Show();
}

private void Button9_Click(object sender, EventArgs e)
{
List<Rectangle> 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<int, Rectangle> Rectangle = Advanced.FindDockedTaskbarsDictionary;

foreach (KeyValuePair<int, Rectangle> 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);
}
}
}
}
Loading

0 comments on commit 20ab538

Please sign in to comment.