Page 1 of 1

Windows TaskBar info

Posted: Thu Mar 15, 2012 4:35 pm
by Tenaja
While adding the Snap to Window Height, I wanted to make the Task Bar height system-aware, rather than a constant. I came across this post on c#, so I converted some of its functionality to PB, but in two procs.
http://www.pcreview.co.uk/forums/taskba ... 87688.html

Right now, I used two procs for the two return values, and I left in all of the debug info. I hope someone can appreciate it.

Also, if anybody has a Linux or Mac version, that would be great.

PB code:

Code: Select all

;  Enum ABMsg 
Enumeration
	#ABM_NEW = 0
	#ABM_REMOVE = 1
	#ABM_QUERYPOS = 2
	#ABM_SETPOS = 3
	#ABM_GETSTATE = 4
	#ABM_GETTASKBARPOS = 5
	#ABM_ACTIVATE = 6
	#ABM_GETAUTOHIDEBAR = 7
	#ABM_SETAUTOHIDEBAR = 8
	#ABM_WINDOWPOSCHANGED = 9
	#ABM_SETSTATE = 10
EndEnumeration


;  Enum ABEdge
Enumeration 
	#ABE_LEFT = 0
	#ABE_TOP
	#ABE_RIGHT
	#ABE_BOTTOM
EndEnumeration

;  Enum ABState
Enumeration
	#ABS_MANUAL = 0
	#ABS_AUTOHIDE = 1
	#ABS_ALWAYSONTOP = 2
	#ABS_AUTOHIDEANDONTOP = 3
EndEnumeration

;  Enum TaskBarEdge
Enumeration 
	#Bottom
	#Top
	#Left
	#Right
EndEnumeration


Procedure.i GetTaskBarHeight()
	abd.APPBARDATA	;APPBARDATA abd = new APPBARDATA();
	
	height = 0
	taskBarEdge = #Bottom
	
	; TaskBarEdge & Height
	SHAppBarMessage_(#ABM_GETTASKBARPOS, abd)
	Select (abd\uEdge)
			Case #ABE_BOTTOM:
					Debug "Taskbar on bottom."
					Debug "bottom=" + Str(abd\rc\bottom) + ", top=" +Str(abd\rc\top)
					taskBarEdge = #Bottom
					height = abd\rc\bottom - abd\rc\top
			Case #ABE_TOP:
					Debug "Taskbar on top."
					Debug "bottom=" + Str(abd\rc\bottom) + ", top= NA"
					taskBarEdge = #Top
					height = abd\rc\bottom
			Case #ABE_LEFT:
					Debug "Taskbar on left."
					Debug "right=" + Str(abd\rc\right) + ", left=" +Str(abd\rc\left)
					taskBarEdge = #Left;
					height = abd\rc\right - abd\rc\left
			Case #ABE_RIGHT:
					Debug "Taskbar on right."
					Debug "right=" + Str(abd\rc\right) + ", left=" +Str(abd\rc\left)
					taskBarEdge = #Right
					height = abd\rc\right - abd\rc\left
	EndSelect
	Debug "hgt = " + Str(height)
	ProcedureReturn height
EndProcedure

Procedure.i GetTaskBarAutoHide()
		
	autoHide = false
	; TaskBar AutoHide Property
	abd.APPBARDATA	;abd = new APPBARDATA();
	uState.i = SHAppBarMessage_(#ABM_GETSTATE, abd);
	Select (uState)
			Case #ABS_ALWAYSONTOP:
					autoHide = #False
			Case #ABS_AUTOHIDE:
					autoHide = #True
			Case #ABS_AUTOHIDEANDONTOP:
					autoHide = #True
			Case #ABS_MANUAL:
					autoHide = #False
	EndSelect
	
	Debug "autohide = " + Str(autoHide)
	ProcedureReturn autoHide
EndProcedure


Debug "height return value: " + Str(GetTaskBarHeight())
Debug "AutoHide return value: " + Str(GetTaskBarAutoHide())

Re: Windows TaskBar info

Posted: Sun Mar 25, 2012 7:01 am
by rudz
Works nicely. Could come in handy :-)

Re: Windows TaskBar info

Posted: Thu Mar 29, 2012 5:47 pm
by SFSxOI
@Tenaja - thanks for posting this, it was very timely because just had an occaision to use something like this.

Re: Windows TaskBar info

Posted: Thu Mar 29, 2012 6:54 pm
by Tenaja
Glad you could use it. Someone might find this one helpful, too; it is a one-call proc that returns all of the data in a structure. Fewer calls, but more typing to use the data. (And slower, if you don't need all of the data.)

Again, this is Windows-only, which I prefer to avoid, but sometimes it is unavoidable. If any Linux or Mac users wish to chip in a conversion, I'd appreciate it.

Code: Select all

Enumeration 
	#ABE_LEFT = 0
	#ABE_TOP
	#ABE_RIGHT
	#ABE_BOTTOM
EndEnumeration

;  Enum ABState
Enumeration
	#ABS_MANUAL = 0
	#ABS_AUTOHIDE = 1
	#ABS_ALWAYSONTOP = 2
	#ABS_AUTOHIDEANDONTOP = 3
EndEnumeration

;  Enum TaskBarEdge
Enumeration 
	#Bottom
	#Top
	#Left
	#Right
EndEnumeration

Structure TaskBarStruct
	AutoHide.i
	State.i
	Height.i
; 	Bottom.i		;optional to insert...
; 	Top.i
; 	Left.i
; 	Right.i
	Loc.i
EndStructure

; --------------

Procedure.i GetAllTaskBarInfo(*TaskBar.TaskBarStruct)
	
	*TaskBar\AutoHide = false	;init the "return" value

	; TaskBar AutoHide Property
	abd.APPBARDATA	;abd = new APPBARDATA();
	*TaskBar\State = SHAppBarMessage_(#ABM_GETSTATE, abd);
	Select (*TaskBar\State)
			Case #ABS_ALWAYSONTOP:
					*TaskBar\AutoHide = #False
			Case #ABS_AUTOHIDE:
					*TaskBar\AutoHide = #True
			Case #ABS_AUTOHIDEANDONTOP:
					*TaskBar\AutoHide = #True
			Case #ABS_MANUAL:
					*TaskBar\AutoHide = #False
	EndSelect
	
	
	abd.APPBARDATA	;APPBARDATA abd = new APPBARDATA();
	
	; Init "return" values
	*TaskBar\Height = 0
	*TaskBar\Loc = #Bottom
	
	; TaskBar Location & Height
	SHAppBarMessage_(#ABM_GETTASKBARPOS, abd)
	Select (abd\uEdge)
			Case #ABE_BOTTOM:
					*TaskBar\Loc = #Bottom
					*TaskBar\height = abd\rc\bottom - abd\rc\top
			Case #ABE_TOP:
					*TaskBar\Loc = #Top
					*TaskBar\height = abd\rc\bottom
			Case #ABE_LEFT:
					*TaskBar\Loc = #Left
					*TaskBar\height = abd\rc\right - abd\rc\left
			Case #ABE_RIGHT:
					*TaskBar\Loc = #Right
					*TaskBar\height = abd\rc\right - abd\rc\left
	EndSelect
EndProcedure
; --------------

; 
; ; Use this to demo it:
; Global TaskBar.TaskBarStruct
; 
; GetAllTaskBarInfo(@TaskBar)
; 
; Debug "AutoHide return value: " + Str(TaskBar\AutoHide)
; Debug "height return value: " + Str(TaskBar\Height)
; Debug "Location return value: " + Str(TaskBar\Loc)

Re: Windows TaskBar info

Posted: Mon Jan 06, 2020 12:38 am
by charvista
This post is almost 8 years old, and it still works on Win10 !
I needed to know how to know which edge the taskbar used, whether it is in autohide mode, and the size of the taskbar.
Thank you Tenaja, very helpful !
But, when the taskbar is automatically hidden, there are still 2 pixels visible, so it is not really 0.... We need to take this in account.

Re: Windows TaskBar info

Posted: Mon Jan 06, 2020 9:14 am
by BarryG
charvista wrote:whether it is in autohide mode
I need to know this, too!

Re: Windows TaskBar info

Posted: Mon Jan 06, 2020 6:57 pm
by charvista
BarryG wrote:I need to know this, too!
Here a simplification to know the Taskbar AutoHide Status:

Code: Select all

EnableExplicit

Procedure.i TaskbarStatus()
    Protected.i abd.APPBARDATA,uState
    abd.APPBARDATA
    abd\cbSize = SizeOf(abd)
    uState.i=SHAppBarMessage_(#ABM_GETSTATE,abd)
    ; #ABS_MANUAL           = 0 = NOT in autohide mode
    ; #ABS_AUTOHIDE         = 1 = in autohide mode
    ; #ABS_ALWAYSONTOP      = 2 = NOT in autohide mode
    ; #ABS_AUTOHIDEANDONTOP = 3 = in autohide mode
    ProcedureReturn uState.i
EndProcedure

Define.i S

S=TaskbarStatus()
If S=1 Or S=3
    MessageRequester("Taskbar Status","AutoHide is ON",#PB_MessageRequester_Info)
Else
    MessageRequester("Taskbar Status","AutoHide is OFF",#PB_MessageRequester_Info)
EndIf
Hope it helps you :D

Re: Windows TaskBar info

Posted: Fri Jan 10, 2020 6:26 pm
by Tenaja
charvista wrote:This post is almost 8 years old, and it still works on Win10 !
I needed to know how to know which edge the taskbar used, whether it is in autohide mode, and the size of the taskbar.
Thank you Tenaja, very helpful !
But, when the taskbar is automatically hidden, there are still 2 pixels visible, so it is not really 0.... We need to take this in account.
I'm glad people are still finding it helpful. Nowadays I just get to come here and dream about having time to code. :?

Thank you for pointing out the extra 2 pixels. It might be a border width setting or something like that--care to check and report back? Or, is it always 2 pixels regardless of the dpi?