Option Explicit
#If VBA7 Then
#If Win64 Then
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
#Else
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function GetWindowLong Lib "USER32.DLL" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
#End If
Private Declare PtrSafe Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As PAPPBARDATA) As LongPtr
Private Declare PtrSafe Function FindWindow Lib "USER32.DLL" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#Else
Private Enum LongPtr
[_]
End Enum
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "USER32.DLL" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As PAPPBARDATA) As Long
Private Declare Function FindWindow Lib "USER32.DLL" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If
Private Type PAPPBARDATA
cbSize As Long
hwnd As LongPtr
Bytes(0& To 23&) As Byte
lParam As Long
End Type
Sub ToggleTaskBarAutoHide()
#If Win64 Then
Const NULL_PTR = 0^
#Else
Const NULL_PTR = 0&
#End If
Const ABM_GETSTATE = &H4, ABM_SETSTATE = &HA
Const ABS_ALWAYSONTOP = &H2, ABS_AUTOHIDE = &H1
Dim uData As PAPPBARDATA
MakeVBEChild(FindWindow("wndclass_desked_gsk", vbNullString)) = True
With uData
.hwnd = FindWindow("Shell_TrayWnd", vbNullString)
.cbSize = LenB(uData)
If SHAppBarMessage(ABM_GETSTATE, uData) = NULL_PTR Then
.lParam = ABS_AUTOHIDE
Else
.lParam = ABS_ALWAYSONTOP
End If
Call SHAppBarMessage(ABM_SETSTATE, uData)
End With
MakeVBEChild(FindWindow("wndclass_desked_gsk", vbNullString)) = False
End Sub
Private Property Let MakeVBEChild(ByVal hwnd As LongPtr, ByVal vNewValue As Boolean)
Const GWL_STYLE = (-16&), WS_CHILD = &H40000000
Dim lNewStyle As Long
If vNewValue Then
lNewStyle = GetWindowLong(hwnd, GWL_STYLE) Or WS_CHILD
Else
lNewStyle = GetWindowLong(hwnd, GWL_STYLE) And Not WS_CHILD
End If
DoEvents
Call SetWindowLong(hwnd, GWL_STYLE, lNewStyle)
End Property