Taskbard - taskbarautohidernot
Toggle your taskbar's auto-hide faster than you can say "Where'd my taskbar go?"
This program demonstrates how to toggle the auto-hide functionality of the Windows taskbar using C# and Windows API calls.
Downloads:- taskbarautohideornot taskbarautohidernot.exe .Net 8 published as a win32 single file exe [(v 1.0) Monday, March 24, 2025 11:07:38 PM]
- taskbard.exe taskbard.exeConsole app .Net 8 published as a win32 single file exe. [(v 1.0) 3/24/2025]
What does it do?
- It will change the Auto-Hide taskbar setting on your Windows Taskbar. As if you used the 'Taskbar Behaviors' settings and changed 'Automatically Hide the Taskbar' setting.
Why does it exist?
To have a button on a Streamdeck that will toggle the Taskbar Auto-Hide setting without a bunch of clicks.
Rather than try to find the hidden taskbar (once hidden under an ACTIVE DESKTOP APPLICATION) just run the app!
It is doing is the same thing you can do from the Taskbar 'behavior' settings when you enable or disable "automatically hide the taskbar". This little bit of code make it super simple to find the task bar and change that setting with just a single click that you can run from a shortcut or from a button on your stream deck.
How to use
- Just download and run it, each time its run it will toggle the Taskbar Autohide setting to Enable or Disable. -- or if you are so inclined --
- Copy the code below into a new project i used VS 2022 as a new Windows Deskopt App (WinForm or Console) it just worked for me.
What Versions are supported?
This is Developed using .Net and Windows 11 24H2 but its been tested and us used with both 11 23H2 and Windows 10 22H2. If you dont have the .Net files installed you may be prompted to get them from Microsoft.Overview
The program achieves the following:
- Identifies the Windows taskbar using the
FindWindow
API. S
- Queries the current auto-hide state of the taskbar.
- Toggles the auto-hide state using
SHAppBarMessage
. - Displays the updated state in the console.
Code
Below is the full source code written in C#:
using System;
using System.Runtime.InteropServices;
class Program
{
private const int ABM_GETSTATE = 0x00000004;
private const int ABM_SETAUTOHIDEBAREX = 0x0000000a;
[DllImport("shell32.dll", CallingConvention = CallingConvention.StdCall)]
private static extern uint SHAppBarMessage(uint dwMessage, ref APPBARDATA pData);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[StructLayout(LayoutKind.Sequential)]
private struct APPBARDATA
{
public uint cbSize;
public IntPtr hWnd;
public uint uCallbackMessage;
public uint uEdge;
public RECT rc;
public int lParam;
}
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
static void Main()
{
try
{
IntPtr taskbarHandle = FindWindow("Shell_TrayWnd", null);
if (taskbarHandle == IntPtr.Zero)
throw new InvalidOperationException("Taskbar window not found.");
uint screenEdge = 3; // Bottom edge
bool newState = ToggleAutoHide(taskbarHandle, screenEdge);
Console.WriteLine($"Auto-hide is now {(newState ? "enabled" : "disabled")}.");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
static bool ToggleAutoHide(IntPtr taskbarHandle, uint screenEdge)
{
APPBARDATA appBarData = new APPBARDATA
{
cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)),
hWnd = taskbarHandle,
uEdge = screenEdge
};
// Check current auto-hide state
bool isAutoHideEnabled = IsAutoHideEnabled(appBarData);
appBarData.lParam = isAutoHideEnabled ? 0 : 1; // Toggle state
uint result = SHAppBarMessage(ABM_SETAUTOHIDEBAREX, ref appBarData);
if (result == 0)
{
throw new InvalidOperationException("Failed to toggle auto-hide state.");
}
return !isAutoHideEnabled; // Return the new state
}
static bool IsAutoHideEnabled(APPBARDATA appBarData)
{
uint state = SHAppBarMessage(ABM_GETSTATE, ref appBarData);
return (state & 0x01) != 0; // Auto-hide flag
}
}
GUI Code Alternative
Below is the GUI source code written in C#:
Alternative Approach: Issue: if you dont like the console window flashing here is another way to do it with a GUI app.- 1. Project Type: Set the project to Windows Application in Visual Studio properties to eliminate the console window.
- 2. Replaced Console.WriteLine with Errors and statuses are logged to TaskbarToggleLog.txt.
using System;
using System.Runtime.InteropServices;
class Program
{
private const int ABM_GETSTATE = 0x00000004;
private const int ABM_SETAUTOHIDEBAREX = 0x0000000a;
[DllImport("shell32.dll", CallingConvention = CallingConvention.StdCall)]
private static extern uint SHAppBarMessage(uint dwMessage, ref APPBARDATA pData);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[StructLayout(LayoutKind.Sequential)]
private struct APPBARDATA
{
public uint cbSize;
public IntPtr hWnd;
public uint uCallbackMessage;
public uint uEdge;
public RECT rc;
public int lParam;
}
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[STAThread]
static void Main()
{
try
{
// Prevents flashing console window
IntPtr taskbarHandle = FindWindow("Shell_TrayWnd", null);
if (taskbarHandle == IntPtr.Zero)
throw new InvalidOperationException("Taskbar window not found.");
uint screenEdge = 3; // Bottom edge
bool newState = ToggleAutoHide(taskbarHandle, screenEdge);
// Optional: Write output to a log file instead of using Console
System.IO.File.AppendAllText("TaskbarToggleLog.txt",
$"Auto-hide is now {(newState ? "enabled" : "disabled")}. Timestamp: {DateTime.Now}\n");
}
catch (Exception ex)
{
// Handle errors silently or log them
System.IO.File.AppendAllText("TaskbarToggleLog.txt",
$"Error: {ex.Message}. Timestamp: {DateTime.Now}\n");
}
}
static bool ToggleAutoHide(IntPtr taskbarHandle, uint screenEdge)
{
APPBARDATA appBarData = new APPBARDATA
{
cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)),
hWnd = taskbarHandle,
uEdge = screenEdge
};
// Check current auto-hide state
bool isAutoHideEnabled = IsAutoHideEnabled(appBarData);
appBarData.lParam = isAutoHideEnabled ? 0 : 1; // Toggle state
uint result = SHAppBarMessage(ABM_SETAUTOHIDEBAREX, ref appBarData);
if (result == 0)
{
throw new InvalidOperationException("Failed to toggle auto-hide state.");
}
return !isAutoHideEnabled; // Return the new state
}
static bool IsAutoHideEnabled(APPBARDATA appBarData)
{
uint state = SHAppBarMessage(ABM_GETSTATE, ref appBarData);
return (state & 0x01) != 0; // Auto-hide flag
}
}