- Offizieller Beitrag
Hi,
ich war zwar der Meinung, ich hätte diese Funktion schon mal erstellt - aber ich konnte es nicht mehr finden. ![]()
Also somit (evtl. zum zweiten mal) will ich euch nicht davon verschonen. ![]()
Mit der Funktion lassen sich Maße und Position der Taskleiste ermitteln.
EDIT 2021-01-21
Ich habe mir die Funktion nochmals vorgesucht und die damaligen Fehler in der 2.ten Version korrigiert. Die Werte für die Anordnung sind jetzt auch konform mit Windows (im Uhrzeigersinn: 0=links, 1=oben, 2=rechts, 3=unten). Alles andere erklärt sich selbst.
;-- TIME_STAMP 2021-01-21 13:19:07 v 0.1
Local $tTB = _GetTaskBarProps(True)
ConsoleWrite( _
'hWnd: ' & $tTB.hWnd & @CRLF & _
'Autohide: ' & $tTB.autohide & @CRLF & _
'uEdge: ' & $tTB.uEdge & @CRLF & _
'sEdge: ' & $tTB.sEdge & @CRLF & _
'Rect: ' & '[' & $tTB.left & ', ' & $tTB.top & ', ' & $tTB.right & ', ' & $tTB.bottom & ']' & @CRLF)
;===================================================================================================
; Function Name....: _GetTaskBarProps
; Description......: gibt Eigenschaften und Position der Taskbar zurück
; Parameter(s).....: [optional] $_bReturnStruct - Rückgabe als (True) Struktur, (False - Standard) Array
; Return Value(s)..: Array / Struktur mit den Taskbarwerten
;===================================================================================================
Func _GetTaskBarProps($_bReturnStruct=False)
Local Const $ABM_GETSTATE = 0x4 ; specify the cbSize.
Local Const $ABM_GETTASKBARPOS = 0x5 ; specify the cbSize.
Local Const $ABM_GETAUTOHIDEBAR = 0x7 ; specify the cbSize and uEdge. Returns the handle to the autohide appbar
; ABM_GETSTATE
Local Const $ABS_AUTOHIDE = 0x1
Local Const $ABS_ALWAYSONTOP = 0x2 ; ab Win7 nicht mehr!! --> wenn NICHT $ABS_AUTOHIDE ist es $ABS_ALWAYSONTOP
; uEdge - ABM_GETAUTOHIDEBAR
Local Const $ABE_LEFT = 0
Local Const $ABE_TOP = 1
Local Const $ABE_RIGHT = 2
Local Const $ABE_BOTTOM = 3
Local $hWndAppBar = DllCall("user32.dll", 'long', "FindWindowA", 'str', "Shell_traywnd", 'str', "")[0]
Local $iState, $iEdge, $hWnd, $shell32 = DllOpen("shell32")
Local $tRC = DllStructCreate("struct;int left;int top;int right;int bottom;endstruct")
Local $tAPPBARDATA = DllStructCreate("dword cbSize;int hWnd;uint;uint uEdge;int left;int top;int right;int bottom;int")
$tAPPBARDATA.cbSize = DllStructGetSize($tAPPBARDATA)
$tAPPBARDATA.hWnd = $hWndAppBar
; get pos
$ret = DllCall($shell32, 'int', 'SHAppBarMessage', 'int', $ABM_GETTASKBARPOS, 'ptr', DllStructGetPtr($tAPPBARDATA))
For $i = 1 To 4
DllStructSetData($tRC, $i, DllStructGetData($tAPPBARDATA, $i+4))
Next
; get state
$ret = DllCall($shell32, 'int', 'SHAppBarMessage', 'int', $ABM_GETSTATE, 'ptr', DllStructGetPtr($tAPPBARDATA))
$iState = $ret[0]
; get Edge
If $iState = $ABS_AUTOHIDE Then
For $i = 0 To 3
$tAPPBARDATA.uEdge = $i
$ret = DllCall($shell32, 'int', 'SHAppBarMessage', 'int', $ABM_GETAUTOHIDEBAR, 'ptr', DllStructGetPtr($tAPPBARDATA))
$hWnd = $ret[0]
If $hWnd Then
$iEdge = $i
ExitLoop
EndIf
Next
DllClose($shell32)
Else
If $tRC.top < 1 And $tRC.left < 1 Then
If $tRC.bottom > $tRC.right Then $iEdge = 0
If $tRC.right > $tRC.bottom Then $iEdge = 1
ElseIf $tRC.top < 1 And $tRC.left > 0 Then
$iEdge = 2
Else
$iEdge = 3
EndIf
EndIf
; return array or structure: [.hWnd, .autohide(True/False), .uEdge(0..3), .sEdge(left..bottom), .left, .top, .right, .bottom]
Local $aEdge[] = ['LEFT','TOP','RIGHT','BOTTOM']
Local $aRet[] = [$hWndAppBar, ($iState = $ABS_AUTOHIDE), $iEdge, $aEdge[$iEdge], $tRC.left, $tRC.top, $tRC.right, $tRC.bottom]
Local $tRet = DllStructCreate('int hWnd;bool autohide;uint uEdge;char sEdge[' & StringLen($aEdge[$iEdge]) & '];int left;int top;int right;int bottom;')
For $i = 0 To UBound($aRet) -1
DllStructSetData($tRet, $i+1, $aRet[$i])
Next
Return ($_bReturnStruct ? $tRet : $aRet)
EndFunc ;==>_GetTaskBarProps
Alles anzeigen
Die alten Versionen belasse ich aber mal im Post.
_GetTaskBarProps (veraltet)
ConsoleWrite("TOP" & @TAB & _GetTaskBarProps('top') & @CRLF)
ConsoleWrite("LEFT" & @TAB & _GetTaskBarProps('left') & @CRLF)
ConsoleWrite("HEIGHT" & @TAB & _GetTaskBarProps('height') & @CRLF)
ConsoleWrite("WIDTH" & @TAB & _GetTaskBarProps('width') & @CRLF)
ConsoleWrite("ALIGN" & @TAB & _GetTaskBarProps('align') & @CRLF & @CRLF)
$aProps = _GetTaskBarProps()
ConsoleWrite("LEFT" & @TAB & $aProps[0] & @CRLF)
ConsoleWrite("TOP" & @TAB & $aProps[1] & @CRLF)
ConsoleWrite("RIGHT" & @TAB & $aProps[2] & @CRLF)
ConsoleWrite("BOTTOM" & @TAB & $aProps[3] & @CRLF)
;===============================================================================
; Function Name: _GetTaskBarProps($hProperty="")
; Description:: Ermittelt Taskbareigenschaften
; Parameter(s): $hProperty Eigenschaft, die zurückgegeben werden soll
; "" (Standard) gibt Rectanglposition als Array zurück [left,top,right,bottom]
; "TOP" - X1 obere Position
; "LEFT" - Y1 linke Position
; "HEIGHT" - Y2-Y1 Höhe der Taskleiste
; "WIDTH" - X2-X1 Breite der Taskleiste
; "ALIGN" - Anordnung: 1=links, 2=rechts, 3=oben, 4=unten
; Return Value(s): s. $hProperty
; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
;===============================================================================
Func _GetTaskBarProps($hProperty="")
Local $tRect = DllStructCreate("long;long;long;long"), $hWnd, $ret
$hProperty = StringUpper(StringStripWS($hProperty, 3))
$ret = DllCall("user32.dll", 'long', "FindWindowA", 'str', "Shell_traywnd", 'str', "")
$hWnd = $ret[0]
DllCall("User32.dll", "int", "GetWindowRect", "hwnd", $hWnd, "ptr", DllStructGetPtr($tRect))
Local $left = DllStructGetData($tRect, 1)
Local $top = DllStructGetData($tRect, 2)
Local $right = DllStructGetData($tRect, 3)
Local $bottom = DllStructGetData($tRect, 4)
If $hProperty = "" Then
Local $aOut[4] = [$left, $top, $right, $bottom]
Return $aOut
EndIf
Switch $hProperty
Case "TOP"
Return $top
Case "LEFT"
Return $left
Case "HEIGHT"
Return $bottom - $top
Case "WIDTH"
Return $right - $left
Case "ALIGN"
If $top < 1 Then
If $left < 1 Then
If $bottom > $right Then Return 1
If $right > $bottom Then Return 3
EndIf
EndIf
If $top < 1 Then
If $left > 0 Then Return 2
EndIf
If $left < 1 Then
If $top > 0 Then Return 4
EndIf
EndSwitch
EndFunc ;==>_GetTaskBarProps
_GetTaskBarProps2 (veraltet)
ConsoleWrite(_GetTaskBarProps2() & @CRLF)
; gibt Eigenschaft(en) und Position der Taskbar zurück
Func _GetTaskBarProps2()
Global Const $ABM_NEW = 0x0
Global Const $ABM_REMOVE = 0x1
Global Const $ABM_QUERYPOS = 0x2
Global Const $ABM_SETPOS = 0x3
Global Const $ABM_GETSTATE = 0x4
Global Const $ABM_GETTASKBARPOS = 0x5
Global Const $ABM_ACTIVATE = 0x6
Global Const $ABM_GETAUTOHIDEBAR = 0x7
Global Const $ABM_SETAUTOHIDEBAR = 0x8
Global Const $ABM_WINDOWPOSCHANGED = 0x9
Global Const $ABN_STATECHANGE = 0x0
Global Const $ABN_POSCHANGED = 0x1
Global Const $ABN_FULLSCREENAPP = 0x2
Global Const $ABN_WINDOWARRANGE = 0x3
Global Const $ABS_AUTOHIDE = 0x1
Global Const $ABS_ALWAYSONTOP = 0x2
Global Const $ABE_LEFT = 0
Global Const $ABE_TOP = 1
Global Const $ABE_RIGHT = 2
Global Const $ABE_BOTTOM = 3
Local $hWndAppBar, $msg = '', $ret
Local $tRECT = DllStructCreate('long;long;long;long')
Local $tAPPBARDATA = DllStructCreate( _
'long cbSize;' & _
'hwnd hWnd;' & _
'long uCallbackMessage;' & _
'long uEdge;' & _
'ptr ' & DllStructGetPtr($tRECT) & ';' & _
'long lParam')
DllStructSetData($tAPPBARDATA, 'cbSize', DllStructGetSize($tAPPBARDATA))
$ret = DllCall("shell32", 'long', 'SHAppBarMessage', 'long', $ABM_GETSTATE, 'ptr', DllStructGetPtr($tAPPBARDATA))
$state = $ret[0]
Switch $state
Case False
$msg &= "Auto Hide= False, Always on Top = False." & @CRLF
Case $ABS_ALWAYSONTOP
$msg &= "Always on Top = True." & @CRLF
Case Else
$msg &= "Auto Hide = True." & @CRLF
EndSwitch
For $position = $ABE_LEFT To $ABE_BOTTOM
DllStructSetData($tAPPBARDATA, 'uEdge', $position)
$ret = DllCall("shell32", 'long', 'SHAppBarMessage', 'long', $ABM_GETAUTOHIDEBAR, 'ptr', DllStructGetPtr($tAPPBARDATA))
$hWndAppBar = $ret[0]
If $hWndAppBar > 0 Then
Switch $position
Case $ABE_LEFT
$msg &= "LEFT "
Case $ABE_TOP
$msg &= "TOP "
Case $ABE_RIGHT
$msg &= "RIGHT "
Case $ABE_BOTTOM
$msg &= "BOTTOM "
EndSwitch
EndIf
Next
Return $msg
EndFunc ;==>_GetTaskBarProps2()