Taskbar "Automatically hide the taskbar in desktop mode"

Post your working scripts, libraries and tools for AHK v1.1 and older
anotherautohotkeyusr
Posts: 21
Joined: 27 Oct 2015, 18:45

Taskbar "Automatically hide the taskbar in desktop mode"

Post by anotherautohotkeyusr » 22 Oct 2018, 11:26

Hello fellow AHKers,

Apologies in advance if this is redundant, but after years of wanting this; I've finally been able to accomplish it. Turns out it was ridiculously simple, at least in Windows 10.

I work via Remote Desktop (RDP/VNC/etc) connections all the time, via a window instead of full screen - e.g. mRemoteNG. I like to keep the Taskbar set to "Automatically hide the taskbar in desktop mode" when logged in locally. This is a pain in the neck though when I connect to a remote computer where that taskbar is also set to "Automatically hide...". Trying to bring up the correct taskbar can be an exercise in pixel perfect mouse orchestrations; or requires clicking into the remote desktop window, or outside of the window to set the keyboard focus as desired.

I put together the script below that I compiled and compressed into a little executable. The script will hide the taskbar when hide is passed to it, show the taskbar when show is passed to it; and toggle the taskbar state when nothing or anything else is passed. I created two tasks in Task Scheduler that are triggered by an "On connection to user session" event. The Show Taskbar task's trigger event is set for "Connection from remote computer" while the Hide Taskbar task is set for "Connection from local computer". Now when I connect remotely the Taskbar is set to always be visible, and when I login locally it is automatically hidden.

Any feedback for improvements/best practices/crass stupidity on my part is always appreciated.

Code: Select all

ABS_ALWAYSONTOP   := 2
ABS_AUTOHIDE      := 1
ABM_GETSTATE      := 4
ABM_SETSTATE      := 10
Pointer32bit      := 4
Pointer64bit      := 8
PtrOffSet         := A_PtrSize = Pointer32bit ? 32:40
RequestedCapacity := A_PtrSize = Pointer32bit ? 36:48

Parameter = % A_Args[1]

VarSetCapacity(APPBARDATA, RequestedCapacity)
SHBarState := DllCall("Shell32\SHAppBarMessage", "UInt", ABM_GETSTATE, "Ptr", &APPBARDATA, "Int")

if Parameter = hide
{
	NumPut(ABS_AUTOHIDE, APPBARDATA, PtrOffSet)
}
else
	if Parameter = show
	{
		NumPut(ABS_ALWAYSONTOP, APPBARDATA, PtrOffSet)
	}
	else
	{
		NumPut(SHBarState ? ABS_ALWAYSONTOP:ABS_AUTOHIDE, APPBARDATA, PtrOffSet)
	}

DllCall("Shell32\SHAppBarMessage", "UInt", ABM_SETSTATE, "Ptr", &APPBARDATA)

ExitApp
Cheers my dears. :superhappy:
burakyak
Posts: 3
Joined: 14 Nov 2020, 10:19

Re: Taskbar "Automatically hide the taskbar in desktop mode"

Post by burakyak » 20 Nov 2020, 09:06

It works. This is just what i was looking for. Useful for laptops. Thank you. :bravo:
buliasz
Posts: 26
Joined: 10 Oct 2016, 14:31
Contact:

Re: Taskbar "Automatically hide the taskbar in desktop mode"

Post by buliasz » 26 Jul 2021, 19:25

I've just created simple toggle autohide function based on the above (always on top is ignored anyway in new OSes). Bound to Win+T in my case. It is AHK v2 code:

Code: Select all

#t::			ToggleTaskbar()

ToggleTaskbar() {
	ABM_GETSTATE    := 4
	ABM_SETSTATE    := 10
	is32bit      	:= (A_PtrSize == 4)

	buff := BufferAlloc(is32bit ? 36 : 48, 0)
	oldState := DllCall("Shell32\SHAppBarMessage", "UInt", ABM_GETSTATE, "Ptr", buff, "UInt")
	NumPut("UInt", oldState ^ 1, buff, is32bit ? 32 : 40)
	DllCall("Shell32\SHAppBarMessage", "UInt", ABM_SETSTATE, "Ptr", buff)
}
Post Reply

Return to “Scripts and Functions (v1)”