Get taskbar autohide state? Solved Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Get taskbar autohide state? Solved

29 Oct 2017, 08:48

Im rather active lately here and im awefuly sorry if i ask too many questions, make posts but when i ask, means i couldnt figure it out myself nor was google any help.

So i have this to toggle autohide of taskbar that i found long ago on ahk forums but i actually need a way to get the state of it rather than to set it.
This is the code that toggles it:

Code: Select all

	VarSetCapacity(APPBARDATA, A_PtrSize=4 ? 36:48)
	NumPut(DllCall("Shell32\SHAppBarMessage", "UInt", 4 ; ABM_GETSTATE
											, "Ptr", &APPBARDATA
											, "Int")
	? 2:1, APPBARDATA, A_PtrSize=4 ? 32:40) ; 2 - ABS_ALWAYSONTOP, 1 - ABS_AUTOHIDE
	, DllCall("Shell32\SHAppBarMessage", "UInt", 10 ; ABM_SETSTATE
									   , "Ptr", &APPBARDATA)
How does one make this actually return a value of 1 for autohide enabled and 0 for auto hide disabled?
And in case i or anyone else could ever need that, can we also get the taskbar locked state and always on top as well?
I want to show a custom clock on my screen when taskbar is hidden and for that i need to know when its hidden or not.
Ill experiment still and post any new findings. :)
THANKS GUYS!
Last edited by theimmersion on 29 Oct 2017, 09:37, edited 1 time in total.
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: Get taskbar autohide state?

29 Oct 2017, 09:15

Btw, this is what i use to determine the location of the taskbar.

Code: Select all

Loop
{
	Sleep, 30
	WinGetPos x, y, w, h, ahk_class Shell_TrayWnd
	ScreenCenterW:=(A_ScreenWidth/2)
	ScreenCenterH:=(A_ScreenHeight/2)

	TaskbarLoc:=( w<A_ScreenWidth?(x<ScreenCenterW?"Left":"Right"):(y<ScreenCenterH?"Top":"Bottom") )
	
	Tooltip, %TaskbarLoc%
}
Return
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get taskbar autohide state?  Topic is solved

29 Oct 2017, 09:17

This should do it.

Code: Select all

;ABM_GETSTATE message (Windows)
;https://msdn.microsoft.com/en-us/library/windows/desktop/bb787947(v=vs.85).aspx
;Note  As of Windows 7, ABS_ALWAYSONTOP is no longer returned because the taskbar is always in that state. Older code should be updated to ignore the absence of this value in not assume that return value to mean that the taskbar is not in the always-on-top state.

q:: ;taskbar - toggle auto-hide/always-on-top
vToggle := !vToggle * 0x3
;ABM_SETSTATE := 0xA
VarSetCapacity(APPBARDATA, A_PtrSize=8?48:36, 0)
NumPut(vToggle, &APPBARDATA, A_PtrSize=8?40:32, "UInt")
DllCall("shell32\SHAppBarMessage", UInt,0xA, Ptr,&APPBARDATA, UPtr)
return

w:: ;taskbar - get state - auto-hide/always-on-top
VarSetCapacity(APPBARDATA, A_PtrSize=8?48:36, 0)
;ABM_GETSTATE := 0x4
vState := DllCall("shell32\SHAppBarMessage", UInt,0x4, Ptr,&APPBARDATA, UPtr)

;from shellapi.h
;ABS_ALWAYSONTOP := 0x2 ;ABS_AUTOHIDE := 0x1
MsgBox, % "auto-hide: " (vState & 0x1 ? "on" : "off")
MsgBox, % "always-on-top: " (vState & 0x2 ? "on" : "off")
return
It appears you can't change the on-top status of the taskbar, at least by this method.

Code: Select all

e:: ;attempt to toggle/turn off taskbar always-on-top (didn't work) (tested on Windows 7)
WinGet, vWinExStyle, ExStyle, ahk_class Shell_TrayWnd
MsgBox, % Format("0x{:08X}", vWinExStyle)
;WinSet, ExStyle, ^0x8, ahk_class Shell_TrayWnd
WinSet, ExStyle, 0x80, ahk_class Shell_TrayWnd
return
To lock the taskbar:
taskbar - Lock or disable resizing of task bar autohotkey - Stack Overflow
https://stackoverflow.com/questions/407 ... autohotkey

[EDIT:] Here's some code to get/set the locked state:

Code: Select all

q:: ;taskbar - toggle lock/unlock
PostMessage, 0x111, 424, 0,, ahk_class Shell_TrayWnd
return

w:: ;taskbar - get locked state
RegRead, vIsMovable, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, TaskbarSizeMove
MsgBox, % "taskbar is locked: " (vIsMovable ? "n" : "y")
return
Last edited by jeeswg on 06 Nov 2017, 02:01, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: Get taskbar autohide state?

29 Oct 2017, 09:36

Some express reply, amazing. Thank you very much! This will be very handy.
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: Get taskbar autohide state? Solved

29 Oct 2017, 09:51

One last thing, could someone test my code above and post the screen height with the task bar coords when its up and when down?
In my case, my monitors height is 768 and the taskbar coord is 738 when its poped up and 766 when its poped down.
Im interested if there is always a 2 pixel offset regardles of screen height. This way, could also do stuff when task bar is posped up and down independently. :)

EDIT - this makes the clock not only show when taskbar is on autohide but also, only when its down as well.

Code: Select all

Loop
{
	Sleep, 30
	WinGetPos x, y, w, h, ahk_class Shell_TrayWnd
	ScreenCenterW:=(A_ScreenWidth/2)
	ScreenCenterH:=(A_ScreenHeight/2)

	TaskbarLoc:=( w<A_ScreenWidth?(x<ScreenCenterW?"Left":"Right"):(y<ScreenCenterH?"Top":"Bottom") )
	
	VarSetCapacity(APPBARDATA, A_PtrSize=8?48:36, 0)
	vState := DllCall("shell32\SHAppBarMessage", UInt,0x4, Ptr,&APPBARDATA, UPtr)
	
	AutoHide:=(vState & 0x1 ? "on" : "off")
	AlwaysOnTop:=(vState & 0x2 ? "on" : "off")
	
	if AutoHide="on"
		if (TaskbarLoc="Bottom" and x<(%A_ScreenHeight%-2))
			GoSub, RunClock
		else
			GoSub, CloseClock
}
Return
Happy coding! :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get taskbar autohide state? Solved

29 Oct 2017, 10:06

I tried your script and it returned 'Bottom' all the time. According to my script below, like you, the top of the taskbar was 2 pixels above the bottom of the screen when 'hidden'.

Code: Select all

q:: ;taskbar get position
WinGetPos, vWinX, vWinY, vWinW, vWinH, ahk_class Shell_TrayWnd
MsgBox, % Clipboard := Format("x{} y{} w{} h{}", vWinX, vWinY, vWinW, vWinH)
MsgBox, % A_ScreenWidth " " A_ScreenHeight
return

;x0 y680 w1280 h40 ;shown
;x0 y718 w1280 h40 ;hidden
;w1280 h720 ;screen
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: Get taskbar autohide state? Solved

29 Oct 2017, 10:27

Thank you very much. Alright then, i assume that the offsets arent being modified by different screen sizes so it should work on any screen resolution the same. :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get taskbar autohide state? Solved

06 Nov 2017, 02:02

I added some code above to get/set the locked state.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ntepa and 249 guests