Jump to content

Recommended Posts

Posted

CODE:

; ============================================
; Functions to check taskbar visibility and position
; ============================================

; ------------------------------------------------------------
; Function: _IsTaskbarVisible
; Purpose : Check whether the Windows taskbar is visible
; Return  : True  - Taskbar is visible
;           False - Taskbar is hidden or not found
; Author  : Dao Van Trong - TRONG.PRO
; Example :
;   If _IsTaskbarVisible() Then MsgBox(0, "Status", "Visible")
; ------------------------------------------------------------
Func _IsTaskbarVisible()
    ; Get the handle to the taskbar
    Local $hTaskbar = WinGetHandle("[CLASS:Shell_TrayWnd]")
    If @error Then Return False ; Taskbar not found

    ; Get the position and size of the taskbar
    Local $aPos = WinGetPos($hTaskbar)
    If @error Then Return False

    ; Get the screen dimensions
    Local $iScreenWidth = @DesktopWidth
    Local $iScreenHeight = @DesktopHeight

    ; When the taskbar is hidden, its coordinates may be off-screen:
    ; Top taskbar: Y < 0
    ; Left taskbar: X < 0
    ; Right taskbar: X + Width > DesktopWidth
    ; Bottom taskbar: Y + Height > DesktopHeight

    ; Check if the taskbar is visible
    If $aPos[0] < 0 Or $aPos[1] < 0 Or _
       $aPos[0] + $aPos[2] > $iScreenWidth Or _
       $aPos[1] + $aPos[3] > $iScreenHeight Then
        Return False ; Taskbar is hidden
    Else
        Return True ; Taskbar is visible
    EndIf
EndFunc   ;==>_IsTaskbarVisible

; ------------------------------------------------------------
; Function: _GetTaskbarPosition
; Purpose : Get the position of the Windows taskbar
; Return  : SetError(0, code, "position")
;           code: 1=top, 2=bottom, 3=left, 4=right
;           SetError(3, 0, "unknown") if not determined
; Author  : Dao Van Trong - TRONG.PRO
; Example :
;   $pos = _GetTaskbarPosition()
;   MsgBox(0, "Taskbar Position", $pos & " / code: " & @extended)
; ------------------------------------------------------------
Func _GetTaskbarPosition()
    Local $hTaskbar = WinGetHandle("[CLASS:Shell_TrayWnd]")
    If @error Then Return SetError(1, 0, "") ; Taskbar not found

    Local $aPos = WinGetPos($hTaskbar)
    If @error Then Return SetError(2, 0, "") ; Error getting taskbar position

    Local $iScreenWidth = @DesktopWidth
    Local $iScreenHeight = @DesktopHeight
    Local $tolerance = 5 ; Tolerance threshold in pixels

    ; Check top/bottom positions
    If Abs($aPos[0]) <= $tolerance And Abs($aPos[2] - $iScreenWidth) <= $tolerance Then
        If Abs($aPos[1]) <= $tolerance Then Return SetError(0, 1, "top")
        If Abs($aPos[1] + $aPos[3] - $iScreenHeight) <= $tolerance Then Return SetError(0, 2, "bottom")
    EndIf

    ; Check left/right positions
    If Abs($aPos[1]) <= $tolerance And Abs($aPos[3] - $iScreenHeight) <= $tolerance Then
        If Abs($aPos[0]) <= $tolerance Then Return SetError(0, 3, "left")
        If Abs($aPos[0] + $aPos[2] - $iScreenWidth) <= $tolerance Then Return SetError(0, 4, "right")
    EndIf

    ; If taskbar is hidden, infer its position from off-screen coordinates
    If Not _IsTaskbarVisible() Then
        If $aPos[1] < 0 Then Return SetError(0, 1, "top")
        If $aPos[0] < 0 Then Return SetError(0, 3, "left")
        If $aPos[1] + $aPos[3] - $iScreenHeight > $tolerance Then Return SetError(0, 2, "bottom")
        If $aPos[0] + $aPos[2] - $iScreenWidth > $tolerance Then Return SetError(0, 4, "right")
    EndIf

    Return SetError(3, 0, "unknown") ; Position could not be determined
EndFunc   ;==>_GetTaskbarPosition

;~ ; ------------------------------------------------------------
;~ ; Example usage
;~ ; ------------------------------------------------------------
;~ Local $sPos = _GetTaskbarPosition()
;~ Local $iCode = @extended

;~ If _IsTaskbarVisible() Then
;~     MsgBox(0, "Taskbar Status", _
;~         "Taskbar is visible" & @CRLF & _
;~         "Taskbar position: " & $sPos & @CRLF & _
;~         "Position code : " & $iCode)
;~ Else
;~     MsgBox(0, "Taskbar Status", _
;~         "Taskbar is hidden" & @CRLF & _
;~         "Taskbar position: " & $sPos & @CRLF & _
;~         "Position code : " & $iCode)
;~ EndIf

EG:

; ------------------------------------------------------------
; Example usage
; ------------------------------------------------------------
Local $sPos = _GetTaskbarPosition()
Local $iCode = @extended

If _IsTaskbarVisible() Then
    MsgBox(0, "Taskbar Status", _
        "Taskbar is visible" & @CRLF & _
        "Taskbar position: " & $sPos & @CRLF & _
        "Position code : " & $iCode)
Else
    MsgBox(0, "Taskbar Status", _
        "Taskbar is hidden" & @CRLF & _
        "Taskbar position: " & $sPos & @CRLF & _
        "Position code : " & $iCode)
EndIf

 

Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...