Search code examples
winapiwindows-10windows-explorertaskbar

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


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).


Solution

  • 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.