diff --git a/src/Taskbar/Enum/Enums.cs b/src/Taskbar/Enum/Enums.cs
index c85d69f..735695b 100644
--- a/src/Taskbar/Enum/Enums.cs
+++ b/src/Taskbar/Enum/Enums.cs
@@ -107,7 +107,25 @@ public enum MessageType : uint
SetState = 0x0000000A,
}
- public enum StateType
+ ///
+ ///
+ ///
+ public enum ShowStateType : uint
+ {
+ ///
+ ///
+ ///
+ Hide = 0x00,
+ ///
+ ///
+ ///
+ Show = 0x01
+ }
+
+ ///
+ ///
+ ///
+ public enum HideStateType : uint
{
///
///
diff --git a/src/Taskbar/Struct/Structs.cs b/src/Taskbar/Struct/Structs.cs
new file mode 100644
index 0000000..2736edb
--- /dev/null
+++ b/src/Taskbar/Struct/Structs.cs
@@ -0,0 +1,44 @@
+#region Imports
+
+using System;
+using System.Runtime.InteropServices;
+using Taskbar.Enum;
+
+#endregion
+
+namespace Taskbar.Struct
+{
+ ///
+ ///
+ ///
+ public class Structs
+ {
+ #region Structs
+ ///
+ ///
+ ///
+ [StructLayout(LayoutKind.Sequential)]
+ public struct Data
+ {
+ public uint cbSize;
+ public IntPtr hWnd;
+ public uint uCallbackMessage;
+ public Enums.EdgeType uEdge;
+ public Rectangle rect;
+ public int lParam;
+ }
+
+ ///
+ ///
+ ///
+ [StructLayout(LayoutKind.Sequential)]
+ public struct Rectangle
+ {
+ public int Left;
+ public int Top;
+ public int Right;
+ public int Bottom;
+ }
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/src/Taskbar/Taskbar.cs b/src/Taskbar/Taskbar.cs
index 2310a07..4febeba 100644
--- a/src/Taskbar/Taskbar.cs
+++ b/src/Taskbar/Taskbar.cs
@@ -2,10 +2,11 @@
using System;
using System.Collections.Generic;
-using System.Linq;
+using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Taskbar.Enum;
+using Taskbar.Struct;
#endregion
@@ -23,17 +24,29 @@ namespace Taskbar
{
#region Core
+ ///
+ ///
+ ///
public class Taskbar
{
+ #region Values
///
///
///
- private const string Exception = "It only works on the Windows platform.";
+ private const string Exception = "An unexpected error occurred.";
+
+ ///
+ ///
+ ///
+ private const string ClassName = "Shell_TrayWnd";
+
///
///
///
- private const string OnlyWindows = "It only works on the Windows platform.";
+ private static Structs.Data BarData;
+ #endregion
+ #region Simple Taskbar
///
///
///
@@ -44,28 +57,53 @@ public class Simple
///
///
///
- private static Enums.LocationType Detect(Screen Screen)
+ public static Enums.LocationType Detect(Screen Screen)
{
- if (Screen.WorkingArea.Width == Screen.Bounds.Width)
+ try
{
- if (Screen.WorkingArea.Top > 0)
+ if (Screen.WorkingArea.Width == Screen.Bounds.Width)
{
- return Enums.LocationType.Top;
+ if (Screen.WorkingArea.Top > 0)
+ {
+ return Enums.LocationType.Top;
+ }
+ else
+ {
+ return Enums.LocationType.Bot;
+ }
}
else
{
- return Enums.LocationType.Bot;
+ if (Screen.WorkingArea.Left > 0)
+ {
+ return Enums.LocationType.Left;
+ }
+ else
+ {
+ return Enums.LocationType.Right;
+ }
}
}
- else
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+
+ ///
+ ///
+ ///
+ public static Enums.LocationType SingleDetect
+ {
+ get
{
- if (Screen.WorkingArea.Left > 0)
+ try
{
- return Enums.LocationType.Left;
+ return Detect(Screen.PrimaryScreen);
}
- else
+ catch
{
- return Enums.LocationType.Right;
+ throw new Exception(Exception);
}
}
}
@@ -73,20 +111,46 @@ private static Enums.LocationType Detect(Screen Screen)
///
///
///
- public static Enums.LocationType SingleDetect
+ public static Dictionary MultiDetectDictionary
{
get
{
try
{
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ Dictionary Result = new();
+ int Count = 0;
+
+ foreach (Screen Screen in Screen.AllScreens)
{
- return Detect(Screen.PrimaryScreen);
+ Result.Add(Count++, Detect(Screen));
}
- else
+
+ return Result;
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+ }
+
+ ///
+ ///
+ ///
+ public static List MultiDetectList
+ {
+ get
+ {
+ try
+ {
+ List Result = new();
+
+ foreach (Screen Screen in Screen.AllScreens)
{
- throw new Exception(OnlyWindows);
+ Result.Add(Detect(Screen));
}
+
+ return Result;
}
catch
{
@@ -94,32 +158,174 @@ public static Enums.LocationType SingleDetect
}
}
}
+ }
+ #endregion
+
+ #region Advanced Taskbar
+ ///
+ ///
+ ///
+ public class Advanced
+ {
+ #region DLL Imports
+
+ [DllImport("user32.dll", SetLastError = true)]
+ private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
+
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static extern bool GetWindowRect(IntPtr hWnd, ref Structs.Rectangle lpRect);
+
+ [DllImport("shell32.dll", SetLastError = true)]
+ private static extern IntPtr SHAppBarMessage(Enums.MessageType dwMessage, [In] ref Structs.Data pData);
+
+ [DllImport("user32.dll")]
+ private static extern int ShowWindow(IntPtr hwnd, int command);
+
+ #endregion
///
- ///
+ /// Static initializer of the class.
+ ///
+ static Advanced()
+ {
+ try
+ {
+ BarData = new Structs.Data
+ {
+ cbSize = (uint)Marshal.SizeOf(typeof(Structs.Data)),
+ hWnd = FindWindow(ClassName, null)
+ };
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+
+ ///
+ /// Gets a value indicating whether the taskbar is always on top of other windows.
///
- public static Dictionary MultiDetect
+ /// true if the taskbar is always on top of other windows; otherwise, false.
+ /// This property always returns false on Windows 7 and newer.
+ ///
+ public static bool AlwaysOnTop
{
get
{
try
{
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ int state = SHAppBarMessage(Enums.MessageType.GetState, ref BarData).ToInt32();
+ return !((Enums.ShowStateType)state).HasFlag(Enums.ShowStateType.Show);
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+ }
+
+ ///
+ /// Gets a value indicating whether the taskbar is automatically hidden when inactive.
+ ///
+ /// true if the taskbar is set to auto-hide is enabled; otherwise, false.
+ ///
+ public static bool AutoHide
+ {
+ get
+ {
+ try
+ {
+ int state = SHAppBarMessage(Enums.MessageType.GetState, ref BarData).ToInt32();
+ return ((Enums.HideStateType)state).HasFlag(Enums.HideStateType.Hide);
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+ }
+
+ ///
+ /// Gets the current display bounds of the taskbar.
+ ///
+ public static Rectangle CurrentBounds
+ {
+ get
+ {
+ try
+ {
+ Structs.Rectangle rect = new();
+ if (GetWindowRect(Handle, ref rect))
{
- Dictionary Type = new();
- int Count = 0;
+ return Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom);
+ }
- foreach (Screen Screen in Screen.AllScreens)
- {
- Type.Add(Count++, Detect(Screen));
- }
+ return Rectangle.Empty;
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+ }
- return Type;
+ ///
+ /// Gets the display bounds when the taskbar is fully visible.
+ ///
+ public static Rectangle DisplayBounds
+ {
+ get
+ {
+ try
+ {
+ if (RefreshBoundsAndPosition())
+ {
+ return Rectangle.FromLTRB(BarData.rect.Left, BarData.rect.Top, BarData.rect.Right, BarData.rect.Bottom);
}
- else
+
+ return CurrentBounds;
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+ }
+
+ ///
+ /// Gets the taskbar's window handle.
+ ///
+ private static IntPtr Handle
+ {
+ get
+ {
+ try
+ {
+ return BarData.hWnd;
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+ }
+
+ ///
+ /// Gets the taskbar's position on the screen.
+ ///
+ public static Enums.LocationType Position
+ {
+ get
+ {
+ try
+ {
+ if (RefreshBoundsAndPosition())
{
- throw new Exception(OnlyWindows);
+ return (Enums.LocationType)BarData.uEdge;
}
+
+ return Enums.LocationType.Unknown;
}
catch
{
@@ -127,7 +333,57 @@ public static Enums.LocationType SingleDetect
}
}
}
+
+ ///
+ /// Hides the taskbar.
+ ///
+ public static void Hide()
+ {
+ try
+ {
+ const int SW_HIDE = 0;
+ ShowWindow(Handle, SW_HIDE);
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+
+ ///
+ /// Shows the taskbar.
+ ///
+ public static void Show()
+ {
+ try
+ {
+ const int SW_SHOW = 1;
+ ShowWindow(Handle, SW_SHOW);
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
+
+ ///
+ ///
+ ///
+ ///
+ private static bool RefreshBoundsAndPosition()
+ {
+ try
+ {
+ //! SHAppBarMessage returns IntPtr.Zero **if it fails**
+ return SHAppBarMessage(Enums.MessageType.GetTaskbarPos, ref BarData) != IntPtr.Zero;
+ }
+ catch
+ {
+ throw new Exception(Exception);
+ }
+ }
}
+ #endregion
}
#endregion
diff --git a/src/Taskbar/Taskbar.csproj b/src/Taskbar/Taskbar.csproj
index 196f4f8..3dd790f 100644
--- a/src/Taskbar/Taskbar.csproj
+++ b/src/Taskbar/Taskbar.csproj
@@ -1,10 +1,11 @@
- net48
-
-
-
+
+
+
+ net40;net45;net451;net452;net46;net461;net462;net47;net471;net472;net48;netcoreapp3.0-windows;netcoreapp3.1-windows;net5.0-windows;net6.0-windows
+ true
Resources\ICO.ico
1.0.0.2
$(Version)
@@ -19,7 +20,7 @@
LICENSE
false
- Minor changes have been made.
+ Major changes have been made.
Changes are detailed at https://github.com/Soferity/Taskbar/releases
Taskbar Taiizor Soferity C# CSharp VBC VB VisualBasic DotNET .NET NET Detecting Detection Windows
true
@@ -53,10 +54,6 @@ Changes are detailed at https://github.com/Soferity/Taskbar/releases
-
-
-
-
True
diff --git a/src/Taskbar_CR/Form1.Designer.cs b/src/Taskbar_CR/Form1.Designer.cs
index f568300..86bb26c 100644
--- a/src/Taskbar_CR/Form1.Designer.cs
+++ b/src/Taskbar_CR/Form1.Designer.cs
@@ -31,6 +31,12 @@ private void InitializeComponent()
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button5 = new System.Windows.Forms.Button();
+ this.button6 = new System.Windows.Forms.Button();
+ this.button7 = new System.Windows.Forms.Button();
+ this.button8 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
@@ -45,25 +51,95 @@ private void InitializeComponent()
//
// button2
//
- this.button2.Location = new System.Drawing.Point(171, 12);
+ this.button2.Location = new System.Drawing.Point(168, 12);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(150, 64);
this.button2.TabIndex = 1;
- this.button2.Text = "Simple\r\nMulti Detect";
+ this.button2.Text = "Simple\r\nMulti Detect Dictionary";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.Button2_Click);
//
+ // button3
+ //
+ this.button3.Location = new System.Drawing.Point(12, 96);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(150, 64);
+ this.button3.TabIndex = 2;
+ this.button3.Text = "Advanced\r\nAlways On Top";
+ this.button3.UseVisualStyleBackColor = true;
+ this.button3.Click += new System.EventHandler(this.Button3_Click);
+ //
+ // button4
+ //
+ this.button4.Location = new System.Drawing.Point(168, 96);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(150, 64);
+ this.button4.TabIndex = 3;
+ this.button4.Text = "Advanced\r\nAuto Hide";
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.Button4_Click);
+ //
+ // button5
+ //
+ this.button5.Location = new System.Drawing.Point(324, 96);
+ this.button5.Name = "button5";
+ this.button5.Size = new System.Drawing.Size(150, 64);
+ this.button5.TabIndex = 4;
+ this.button5.Text = "Advanced\r\nPosition";
+ this.button5.UseVisualStyleBackColor = true;
+ this.button5.Click += new System.EventHandler(this.Button5_Click);
+ //
+ // button6
+ //
+ this.button6.Location = new System.Drawing.Point(12, 166);
+ this.button6.Name = "button6";
+ this.button6.Size = new System.Drawing.Size(150, 64);
+ this.button6.TabIndex = 5;
+ this.button6.Text = "Advanced\r\nHide";
+ this.button6.UseVisualStyleBackColor = true;
+ this.button6.Click += new System.EventHandler(this.Button6_Click);
+ //
+ // button7
+ //
+ this.button7.Location = new System.Drawing.Point(168, 166);
+ this.button7.Name = "button7";
+ this.button7.Size = new System.Drawing.Size(150, 64);
+ this.button7.TabIndex = 6;
+ this.button7.Text = "Advanced\r\nShow";
+ this.button7.UseVisualStyleBackColor = true;
+ this.button7.Click += new System.EventHandler(this.Button7_Click);
+ //
+ // button8
+ //
+ this.button8.Location = new System.Drawing.Point(324, 12);
+ this.button8.Name = "button8";
+ this.button8.Size = new System.Drawing.Size(150, 64);
+ this.button8.TabIndex = 7;
+ this.button8.Text = "Simple\r\nMulti Detect List";
+ this.button8.UseVisualStyleBackColor = true;
+ this.button8.Click += new System.EventHandler(this.Button8_Click);
+ //
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
- this.ClientSize = new System.Drawing.Size(333, 473);
+ this.ClientSize = new System.Drawing.Size(486, 241);
+ this.Controls.Add(this.button8);
+ this.Controls.Add(this.button7);
+ this.Controls.Add(this.button6);
+ this.Controls.Add(this.button5);
+ this.Controls.Add(this.button4);
+ this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
+ this.MaximizeBox = false;
+ this.MinimizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
+ this.TopMost = true;
this.ResumeLayout(false);
}
@@ -72,5 +148,11 @@ private void InitializeComponent()
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.Button button3;
+ private System.Windows.Forms.Button button4;
+ private System.Windows.Forms.Button button5;
+ private System.Windows.Forms.Button button6;
+ private System.Windows.Forms.Button button7;
+ private System.Windows.Forms.Button button8;
}
}
\ No newline at end of file
diff --git a/src/Taskbar_CR/Form1.cs b/src/Taskbar_CR/Form1.cs
index 3f5bcd4..ff95d14 100644
--- a/src/Taskbar_CR/Form1.cs
+++ b/src/Taskbar_CR/Form1.cs
@@ -20,12 +20,47 @@ private void Button1_Click(object sender, EventArgs e)
private void Button2_Click(object sender, EventArgs e)
{
- Dictionary Screen = Simple.MultiDetect;
+ Dictionary Screen = Simple.MultiDetectDictionary;
foreach (KeyValuePair Var in Screen)
{
MessageBox.Show(Var.Key + ": " + Var.Value);
}
}
+
+ private void Button8_Click(object sender, EventArgs e)
+ {
+ List Screen = Simple.MultiDetectList;
+
+ foreach (Enums.LocationType Var in Screen)
+ {
+ MessageBox.Show(Var.ToString());
+ }
+ }
+
+ private void Button3_Click(object sender, EventArgs e)
+ {
+ MessageBox.Show(Advanced.AlwaysOnTop.ToString());
+ }
+
+ private void Button4_Click(object sender, EventArgs e)
+ {
+ MessageBox.Show(Advanced.AutoHide.ToString());
+ }
+
+ private void Button5_Click(object sender, EventArgs e)
+ {
+ MessageBox.Show(Advanced.Position.ToString());
+ }
+
+ private void Button6_Click(object sender, EventArgs e)
+ {
+ Advanced.Hide();
+ }
+
+ private void Button7_Click(object sender, EventArgs e)
+ {
+ Advanced.Show();
+ }
}
}
\ No newline at end of file
diff --git a/src/Taskbar_CR/Taskbar_CR.csproj b/src/Taskbar_CR/Taskbar_CR.csproj
index 2c0dae7..83db1ea 100644
--- a/src/Taskbar_CR/Taskbar_CR.csproj
+++ b/src/Taskbar_CR/Taskbar_CR.csproj
@@ -1,13 +1,15 @@
- net48
-
+
+
+ net48;netcoreapp3.0-windows;netcoreapp3.1-windows;net5.0-windows;net6.0-windows
WinExe
false
true
preview
preview
en
+ CA1416
Taskbar_CR.Program