A command or message or DLL call to set automatic hiding of Windows taskbar?
Asked Answered
P

1

3

I need to set or toggle auto-hiding of Windows 10 taskbar programmatically. An action bound to a hotkey for productivity and convenience. Is there a command-line command or a DLL call which allows to achieve equivalent of flipping the following switch:

enter image description here

Currently I am achieving this by opening the above Settings window and sending keystrokes for search, followed by Downs and Space and Alt+F4 but it is slow and unreliable.

This question is not language-specific since DLL calls look pretty much the same everywhere, although my final implementation will be in AutoHotKey.

Expected result: After running the command, the Windows Explorer will change its behavior as if the setting Automatically hide the taskbar in desktop mode was enabled (or disabled or toggled).

Polyglot answered 19/11, 2018 at 1:38 Comment(2)
I think after some searching I was able to find it.Polyglot
Great job, especially sharing the solution. I'm interested in knowing how you sent keystrokes - even if it's imperfect/unreliable, because it's so extremely valuable at times. (MS can go to hell for removing the keystroke recorder that was even in original Windows. That's what would be ideal, however it's in contradiction with MS's world deproductivity objective)Fuel
P
6

It is ABM_SETSTATE message. (Edit: Not since Windows 11.)

After finding the proper Windows message I have also found the implementation in AutoHotKey:

ABM_SETSTATE    := 10
ABS_NORMAL      := 0x0
ABS_AUTOHIDE    := 0x1
ABS_ALWAYSONTOP := 0x2
VarSetCapacity(APPBARDATA, 36, 0)
Address := NumPut(36, APPBARDATA)
Address := NumPut(WinExist("ahk_class Shell_TrayWnd"), Address + 0)
NumPut(ABS_NORMAL, Address + 24)
DllCall("Shell32.dll\SHAppBarMessage", UInt, ABM_SETSTATE, UInt, &APPBARDATA)

Change the parameter in the second line from the bottom from ABS_NORMAL to ABS_AUTOHIDE to achieve the expected other state.

Polyglot answered 19/11, 2018 at 2:33 Comment(2)
This no longer seems to work in Windows 11, at least not when I tested it.Phototherapy
@BeamDavis – good catch. Windows 11 still supports automatic hiding of the taskbar, but this message no longer controls it. After receiving this message, the taskbar only flashes with a quirky behavior and then acts as if there was no change in the setting.Polyglot

© 2022 - 2024 — McMap. All rights reserved.