Jump to content

Functions to interact with the taskbar


ioa747
 Share

Recommended Posts

ygGqQ.thumb.png.0ad468ef5bf3f96aac1fa0c0be295d48.png

 

the script uses CUIAutomation2.au3 UDF from  https://www.autoitscript.com/forum/topic/201683-ui-automation-udfs/

Functions to interact with the taskbar.

; https://www.autoitscript.com/forum/topic/212266-functions-to-interact-with-the-taskbar/
;----------------------------------------------------------------------------------------
; Title...........: _TaskBar.au3
; Description.....: Function to interact with the taskbar.
; AutoIt Version..: 3.3.16.1   Author: ioa747  Script Version: 2.0
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#NoTrayIcon

#include ".Includes\CUIAutomation2.au3" ; * <- "https://www.autoitscript.com/forum/topic/201683-ui-automation-udfs/"
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Example()

;--------------------------------------------------------------------------------------------------------------------------------
Func Example()
    Local $aTBPos, $sTxt, $a

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = ""     ;Get information from NotifyArea
    $sTxt &= "let's take the Everything program for example" & @CRLF
    $sTxt &= 'first we find the tray icon in NotifyArea' & @CRLF
    $sTxt &= '(NotifyArea = $iAreaId 2 )' & @CRLF & @CRLF
    $sTxt &= ' _TaskBar(2, "something not exist")' & @CRLF & @CRLF
    $sTxt &= '$sSearchString = "something not exist"' & @CRLF
    $sTxt &= 'to show us all the results' & @CRLF & @CRLF
    $sTxt &= 'the console only shows results when it doesn''t match' & @CRLF

    _Msg($sTxt)
    _TaskBar(2, "something not exist")

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = ""     ; Double-click in NotifyArea
    $sTxt &= "now we know that the target icon " & @CRLF
    $sTxt &= "starts with the word 'Everything'" & @CRLF & @CRLF
    $sTxt &= "Now we can send Click, Right-click, or Double-click" & @CRLF & @CRLF
    $sTxt &= "send Double-click to tray icon" & @CRLF
    $sTxt &= "(Double-click = $iActionId 4 )" & @CRLF & @CRLF
    $sTxt &= ' _TaskBar(2, "Everything", 4)' & @CRLF

    _Msg($sTxt)
    $aTBPos = _TaskBar(2, "Everything", 4)
    $a = $aTBPos[0][1]
    ConsoleWrite($aTBPos[0][1] & ", Rect: " & $a[0] & ", " & $a[1] & ", " & $a[2] & ", " & $a[3] & @CRLF)



    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = ""     ; Right-click & send in RunningAppsArea
    $sTxt &= "now that the window has opened it created a new" & @CRLF
    $sTxt &= "icon down in the task bar to RunningApps area" & @CRLF & @CRLF
    $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF
    $sTxt &= "(Right-click = $iActionId 3 )" & @CRLF & @CRLF
    $sTxt &= '_TaskBar(1, "Everything", 3, "{UP}{ENTER}")' & @CRLF & @CRLF
    $sTxt &= '$sOption = "{UP}{ENTER}"' & @CRLF
    $sTxt &= 'Right-click and Send' & @CRLF

    _Msg($sTxt)
    _TaskBar(1, "Everything", 3, "{UP}{ENTER}")

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = ""     ; Click&Drag operation
    $sTxt &= "now we move 'Everything' icon from NotifyArea" & @CRLF
    $sTxt &= "to OverflowNotifyArea" & @CRLF & @CRLF
    $sTxt &= '(NotifyArea = $iAreaId 2 )' & @CRLF
    $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF
    $sTxt &= '($sOption = "OverflowButton" )' & @CRLF & @CRLF
    $sTxt &= '_TaskBar(2, "Everything", 5, "OverflowButton")' & @CRLF & @CRLF

    _Msg($sTxt)
    _TaskBar(2, "Everything", 5, "OverflowButton")

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = ""     ; Click&Drag operation
    $sTxt &= "now we move 'Everything' icon from OverflowNotifyArea" & @CRLF
    $sTxt &= "back to NotifyArea at old position" & @CRLF & @CRLF
    $sTxt &= '(OverflowNotifyArea = $iAreaId 3 )' & @CRLF
    $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF
    $sTxt &= '($sOption = "X:" & $a[2] )' & @CRLF & @CRLF
    $sTxt &= '_TaskBar(3, "Everything", 5, "X:" & $a[2])' & @CRLF & @CRLF

    _Msg($sTxt)
    _TaskBar(3, "Everything", 5, "X:" & $a[2])

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = "" ; Right-click & send in RunningAppsArea
    $sTxt &= 'Next step open Notepad' & @CRLF
    $sTxt &= 'Right-click on tray icon and Pin to taskbar' & @CRLF & @CRLF
    $sTxt &= 'Right-click and Send 2 UP && ENTER' & @CRLF
    $sTxt &= ' _TaskBar("Notepad -", 1, 3, "{UP 2}{ENTER}")' & @CRLF

    _Msg($sTxt)

    ShellExecute("notepad")
    WinWaitActive("[CLASS:Notepad]", "")

    _TaskBar(1, "Notepad -", 3, "{UP 2}{ENTER}")
    WinClose("[CLASS:Notepad]", "")

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = "" ; Click&Drag operation
    $sTxt &= "now we move 'Notepad' icon 3 positions to the Left" & @CRLF & @CRLF
    $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF
    $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF
    $sTxt &= '($sOption = -3 )' & @CRLF & @CRLF
    $sTxt &= '_TaskBar(1, "Notepad", 5, -3)' & @CRLF & @CRLF

    _Msg($sTxt)
    _TaskBar(1, "Notepad", 5, -3)

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = "" ; Click&Drag operation
    $sTxt &= "now we move 'Notepad' icon 3 positions to the Right" & @CRLF & @CRLF
    $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF
    $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF
    $sTxt &= '($sOption = 3 )' & @CRLF & @CRLF
    $sTxt &= '_TaskBar(1, "Notepad", 5, 3)' & @CRLF & @CRLF

    _Msg($sTxt)
    _TaskBar(1, "Notepad", 5, 3)

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = "" ; Click&Drag operation
    $sTxt &= "now we move 'Notepad' icon at positions 0" & @CRLF & @CRLF
    $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF
    $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF
    $sTxt &= '($sOption = "index:0" )' & @CRLF & @CRLF
    $sTxt &= '_TaskBar(1, "Notepad", 5, "index:0")' & @CRLF & @CRLF

    _Msg($sTxt)
    _TaskBar(1, "Notepad", 5, "index:0")

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = "" ; Click&Drag operation
    $sTxt &= "now we move 'Notepad' icon at last positions" & @CRLF
    $sTxt &= "by using $sOption = X:n" & @CRLF & @CRLF
    $sTxt &= '(RunningAppsArea = $iAreaId 1 )' & @CRLF
    $sTxt &= "(Click&Drag = $iActionId 5 )" & @CRLF
    $sTxt &= '($sOption = "X:" & @DesktopWidth )' & @CRLF & @CRLF
    $sTxt &= '_TaskBar(1, "Notepad", 5, "X:" & @DesktopWidth)' & @CRLF & @CRLF

    _Msg($sTxt)
    _TaskBar(1, "Notepad", 5, "X:" & @DesktopWidth)
    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    $sTxt = "" ;Get information from RunningAppsArea
    $sTxt &= "at this step" & @CRLF
    $sTxt &= "we trap the Notepad pin with" & @CRLF
    $sTxt &= "($iActionId 1 = Get the button positions and label.)" & @CRLF & @CRLF
    $sTxt &= "move the mouse over the Notepad pin" & @CRLF

    _Msg($sTxt)
    $aTBPos = _TaskBar(1, "Notepad", 1)

    $a = $aTBPos[0][1]
    Local $iMsgBoxAnswer, $bLoop = True

    While $bLoop
        If IsMouseOverRect($a) Then
            $iMsgBoxAnswer = MsgBox(292, "Rect: " & $a[0] & ", " & $a[1] & ", " & $a[2] & ", " & $a[3], "do you want to get out of the loop?")
            Select
                Case $iMsgBoxAnswer = 6 ;Yes
                    $bLoop = False
            EndSelect
        EndIf
        Sleep(300)
    WEnd

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    $sTxt = "" ; Right-click & send in RunningAppsArea
    $sTxt &= 'Now UnPin Notepad pin' & @CRLF
    $sTxt &= 'Right-click and Send UP & ENTER' & @CRLF
    $sTxt &= 'UnPin from taskbar' & @CRLF & @CRLF
    $sTxt &= ' _TaskBar(1, "Notepad -", 3, "{UP}{ENTER}")' & @CRLF & @CRLF
    $sTxt &= 'here attention if there is notepad++ taskpin, it unpin this' & @CRLF
    $sTxt &= 'because it is more forward and starts with word notepad' & @CRLF

    _Msg($sTxt)
    _TaskBar(1, "Notepad", 3, "{UP}{ENTER}")


    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    $sTxt = "" ; Right-click & send in OverflowNotifyArea
    $sTxt &= 'Now for (OverflowNotifyArea = $iAreaId 3 ) ' & @CRLF & @CRLF
    $sTxt &= ' Right-click and Send 5 UP on bluetooth' & @CRLF & @CRLF
    $sTxt &= ' _TaskBar(3, "bluetooth", 3, "{UP 5}")' & @CRLF & @CRLF

    _Msg($sTxt)
    _TaskBar(3, "bluetooth", 3, "{UP 5}")

    Sleep(5000)

    ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    $sTxt = "" ;Get information from RunningAppsArea
    $sTxt &= "or you can call only with the $iAreaId parameter," & @CRLF
    $sTxt &= "1 - Get the button positions and labels" & @CRLF
    $sTxt &= "and take the whole table for any use" & @CRLF & @CRLF
    $sTxt &= '$aTBPos = _TaskBar(1)' & @CRLF & @CRLF

    _Msg($sTxt)
    $aTBPos = _TaskBar(1)

    _ArrayDisplay($aTBPos)

    _Msg("Exit")

EndFunc   ;==>Example
;--------------------------------------------------------------------------------------------------------------------------------
Func _Msg($sMsg)
    Local $hGui = GUICreate("Msg", 395, 237, @DesktopWidth * 0.1, @DesktopHeight * 0.5, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
    GUISetFont(11, 400, 0, "DejaVu Sans Condensed")
    GUICtrlCreateLabel($sMsg, 5, 10, 376, 181)
    Local $Button_OK = GUICtrlCreateButton("OK", 160, 200, 75, 25)
    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button_OK
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hGui)
EndFunc   ;==>_Msg

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: _TaskBar
; Description....: Function to interact with the taskbar.
; Syntax.........: _TaskBar ( $iAreaId = 1, $sSearchString = "@All", $iActionId = 1, $sOption = "", $sUserToolBarPar = "index:1" )
; Parameters.....: $iAreaId       - The ID of Area to interact with. Can be one of the following values:
;                                   1 - RunningAppsArea    - Running applications. (Default)
;                                   2 - NotifyArea         - Notification area.
;                                   3 - OverflowNotifyArea - Overflow Notification Area.
;                  $sSearchString - The string to search for in the button labels. Matches partial string from the start. (Default = "@All")
;                  $iActionId       - The action to perform. Can be one of the following values:
;                                   1 - Get the button positions and labels. (Default)
;                                   2 - Click on a button with the specified label.
;                                   3 - Right-click on a button with the specified label.
;                                   4 - Double-click on a button with the specified label.
;                                   5 - Click&Drag a button with the specified label to specify X axis place
;                  $sOption       - [optional] Additional parameter required by some commands. (Default = "")
;                                   if $iActionId = 2, $sOption = "SendKeys" -  Extra string to send after click.
;                                      "{UP 2}{ENTER}"  send 2 UP and ENTER to elect the specify menu
;                                   if $iActionId = 3, $sOption = "SendKeys" -  Extra string to send after click.
;                                      "o"  send o to select the open menu
;                                   if $iActionId = 5, $sOption = "NumberToMove" -  number of place to move, posive = Right, negative = Left
;                                      "3" move button, 3 positions to the Right
;                                      "-3" move button, 3 positions to the Left
;                                      "index:3" move button, to positions 3
;                                      "X:300" move button, to X coordinate
;                                      "OverflowButton" move button from NotifyArea, to OverflowNotifyArea and vice versa
; Return values..: Success    - An 2D Array containing the rect positions of the button that match the search string.
;                                   $a[i][0]=Label, $a[i][1]=$aRect Array | $aRect[0]=Left, $aRect[1]=Top, $aRect[2]=Right, $aRect[3]=Bottom.
;                             - if $sSearchString does not match, it returns 2D Array of all items.
;                  Failure    - return error message if there is an error.
; Author.........: ioa747
; Modified.......:
; Related .......: This function uses the CUIAutomation2.au3 "https://www.autoitscript.com/forum/topic/201683-ui-automation-udfs/"
; Link ..........:
;--------------------------------------------------------------------------------------------------------------------------------
Func _TaskBar($iAreaId = 1, $sSearchString = "@All", $iActionId = 1, $sOption = "")

    Local $hWndTray = WinGetHandle("[CLASS:Shell_TrayWnd]")  ; Taskbar
    Local $hOverflowButton = ControlGetHandle($hWndTray, "", "Button2")
    Local $hToolbar

    Switch $iAreaId
        Case 1 ;RunningAppsArea
            Local $hRebar = ControlGetHandle($hWndTray, "", "[CLASS:ReBarWindow32]")
            Local $hMSTaskSwWClass = ControlGetHandle($hRebar, "", "[CLASS:MSTaskSwWClass]")
            $hToolbar = ControlGetHandle($hMSTaskSwWClass, "", "[CLASS:MSTaskListWClass]")
        Case 2 ;NotifyArea
            Local $hTrayNotify = ControlGetHandle($hWndTray, "", "[CLASS:TrayNotifyWnd]")
            Local $hSysPager = ControlGetHandle($hTrayNotify, "", "[CLASS:SysPager]")
            $hToolbar = ControlGetHandle($hSysPager, "", "ToolbarWindow321")
        Case 3 ;OverflowNotifyArea
            Local $hWndOverflow = WinGetHandle("[CLASS:NotifyIconOverflowWindow]")
            $hToolbar = ControlGetHandle($hWndOverflow, "", "ToolbarWindow321")

        Case Else
            Return _EW("wrong $iAreaId")
    EndSwitch

    ; https://www.autoitscript.com/forum/topic/133222-manipulate-system-tray-program-right-click-choose-option/page/2/#comment-1499538
    ; Create UI Automation object
    Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
    If Not IsObj($oUIAutomation) Then Return _EW("$oUIAutomation ERR")
    ;ConsoleWrite("$oUIAutomation OK" & @CRLF)

    ; Get Desktop element
    Local $pDesktop, $oDesktop
    $oUIAutomation.GetRootElement($pDesktop)
    $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    If Not IsObj($oDesktop) Then Return _EW("$oDesktop ERR")
    ;ConsoleWrite("$oDesktop OK" & @CRLF)

    ; Get element by handle
    Local $pElement, $oElement
    $oUIAutomation.ElementFromHandle($hToolbar, $pElement)
    $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    If Not IsObj($oElement) Then Return _EW("$oElement ERR")
    ;ConsoleWrite("$oElement OK" & @CRLF)

    ; Get condition (ControlType = Button)
    Local $pCondition, $oCondition
    $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition)
    $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition)
    If Not IsObj($oCondition) Then Return _EW("$oCondition ERR")
    ;ConsoleWrite("$oCondition OK" & @CRLF)

    ; Find all buttons
    Local $pElementArray, $oElementArray, $iElements
    $oElement.FindAll($TreeScope_Children, $oCondition, $pElementArray)
    $oElementArray = ObjCreateInterface($pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
    $oElementArray.Length($iElements)
    If Not IsObj($oElementArray) Then Return _EW("$oElementArray ERR")

    ; Get array of buttons
    Local $aElements[$iElements]
    For $i = 0 To $iElements - 1
        $oElementArray.GetElement($i, $pElement)
        $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
    Next

    ; Get name and position for each button  $UIA_LegacyIAccessibleNamePropertyId
    Local $sValue, $aPos[4], $aBtnArray[$iElements][2]
    Local $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom")

    Local $iChrCnt = StringLen($sSearchString)
    Local $sHelpTxt, $bMatch = False
    Local $aExtract, $aResult

    For $i = 0 To UBound($aElements) - 1
        $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $sValue)
        $aElements[$i].CurrentBoundingRectangle($tRect)
        $aPos[0] = $tRect.Left
        $aPos[1] = $tRect.Top
        $aPos[2] = $tRect.Right
        $aPos[3] = $tRect.Bottom
        $aBtnArray[$i][0] = $sValue
        $aBtnArray[$i][1] = $aPos
        $sHelpTxt &= $i & ") " & $aBtnArray[$i][0] & @CRLF
        If StringLeft($aBtnArray[$i][0], $iChrCnt) = $sSearchString Then
            $aExtract = _ArrayExtract($aBtnArray, $i, $i)
            $bMatch = True
            $sHelpTxt = ""
            ExitLoop
        EndIf
    Next

    $aResult = ($bMatch ? $aExtract : $aBtnArray)

    ; only if $sSearchString not match and <> "@No@"
    If $sSearchString <> "@No@" Then ConsoleWrite($sHelpTxt)

    Local $aMpos, $iAdjust

    Switch $iActionId
        Case 1 ;Get
            Return $aResult

        Case 2, 3, 4 ; 2=$MOUSE_CLICK_LEFT ; 3=$MOUSE_CLICK_RIGHT ; 4=$MOUSE_DBL_CLICK_LEFT
            ; only if $sSearchString match
            If UBound($aResult) = 1 Then
                Local $iClick = ($iActionId = 4 ? 2 : 1)
                Local $iButton = ($iActionId = 3 ? $MOUSE_CLICK_RIGHT : $MOUSE_CLICK_LEFT)
                $aPos = $aResult[0][1]
                ;ConsoleWrite("$aPos =" & $aPos[0] & ", " & $aPos[1] & ", " & $aPos[2] & ", " & $aPos[3] & @CRLF)
                $iAdjust = ($aPos[2] - $aPos[0]) / 2
                $aMpos = MouseGetPos() ;Bakup mouse position
                If $iAreaId = 3 Then ControlClick($hWndTray, "", $hOverflowButton) ;fist click the Overflow Button
                MouseClick($iButton, $aPos[0] + $iAdjust, $aPos[1] + $iAdjust, $iClick, 1)
                If $sOption Then
                    WinActivate($hWndTray)
                    Opt("SendKeyDownDelay", 50) ;you may need to raise
                    Opt("SendKeyDelay", 50) ;you may need to raise
                    Send($sOption)
                    Opt("SendKeyDelay", 5) ;5 milliseconds - Default
                    Opt("SendKeyDownDelay", 5) ;5 milliseconds - Default
                    Send("{ESC}")
                EndIf
                MouseMove($aMpos[0], $aMpos[1], 1) ;restore mouse position
                Return $aResult
            EndIf

        Case 5 ; 5=Click&Drag
            ; only if $sSearchString match
            If UBound($aResult) = 1 Then
                $aPos = $aResult[0][1]
                ;ConsoleWrite("$aPos =" & $aPos[0] & ", " & $aPos[1] & ", " & $aPos[2] & ", " & $aPos[3] & @CRLF)
                $iAdjust = ($aPos[2] - $aPos[0]) / 2
                Local $iBtnWidth = $aPos[2] - $aPos[0]
                Local $iX2
                Local $aOption = StringSplit($sOption, ":")
                If $aOption[0] = 2 Then

                    If $aOption[1] = "X" Then
                        $iX2 = Int($aOption[2])
                        ConsoleWrite("$iX2=" & $iX2 & @CRLF)
                    ElseIf $aOption[1] = "Index" Then
                        Local $aIdx = $iAreaId = 1 ? _TaskBar(1, "@No@") : _TaskBar(2, "@No@")
                        $aOption[2] = Int($aOption[2])
                        If $aOption[2] > UBound($aIdx) - 1 Then Return _EW("wrong Click&Drag $sOption Index:ERR")
                        Local $a = $aIdx[$aOption[2]][1]
                        $iX2 = $a[0]
                    Else
                        Return _EW("wrong Click&Drag $sOption")
                    EndIf

                Else
                    $sOption = Int($sOption)
                    $iX2 = $aPos[0] + $iAdjust + $iBtnWidth * $sOption
                EndIf

                If $sOption = "OverflowButton" Then
                    ; RunningAppsArea not suporting
                    If $iAreaId = 1 Then Return _EW("wrong Click&Drag $sOption, RunningAppsArea not suporting OverflowButton")
                    Local $aCtrlPos = ControlGetPos($hWndTray, "", $hOverflowButton)
                    ;Drag Position = OverflowButton
                    $iX2 = $aCtrlPos[0] + $aCtrlPos[2] / 2
                EndIf

                $aMpos = MouseGetPos() ;Bakup mouse position

                ; if OverflowNotifyArea fist click the Overflow Button
                If $iAreaId = 3 Then ControlClick($hWndTray, "", $hOverflowButton)

                MouseClickDrag($MOUSE_CLICK_LEFT, $aPos[0] + $iAdjust, $aPos[1] + $iAdjust, $iX2, @DesktopHeight - $iAdjust, 1)

                WinActivate($hWndTray)
                Send("{ESC}")

                MouseMove($aMpos[0], $aMpos[1], 1) ;restore mouse position
                Return $aResult
            EndIf

        Case Else
            Return _EW("wrong $iActionId")

    EndSwitch

    ;_ArrayDisplay($aBtnArray)

EndFunc   ;==>_TaskBar
;--------------------------------------------------------------------------------------------------------------------------------
Func IsMouseOverRect($aRect)

    If Not IsArray($aRect) Then Return _EW("Not array found")

    Local $Width = $aRect[2] - $aRect[0]
    Local $Height = $aRect[3] - $aRect[1]
    $aRect[2] = $Width
    $aRect[3] = $Height
    ;$aRect[0]=X ;$aRect[1]=Y ;$aRect[2]=Width ;$aRect[3]=Height
    Local $aMpos = MouseGetPos()
    If $aMpos[0] > $aRect[0] And $aMpos[1] > $aRect[1] And $aMpos[0] < $aRect[0] + $aRect[2] And $aMpos[1] < $aRect[1] + $aRect[3] Then
        Return True
    EndIf
    Return False
EndFunc   ;==>IsMouseOverRect
;--------------------------------------------------------------------------------------------------------------------------------
Func _EW($sString, $iLine = @ScriptLineNumber)
    ConsoleWrite("! (" & $iLine & ") " & $sString & @CRLF)
EndFunc   ;==>_EW
;--------------------------------------------------------------------------------------------------------------------------------

 

And while we're on the subject of TaskBar, here's another related one

;----------------------------------------------------------------------------------------
; Title...........: ShellTrayRefresh.au3
; Description.....: Refreshes ShellTray to remove leftover zombie icons
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
; https://www.autoitscript.com/forum/topic/139260-autoit-snippets/page/25/#comment-1529091
;----------------------------------------------------------------------------------------
Func ShellTrayRefresh()
    Local $aStartPos = MouseGetPos()
    Local $hTrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]")
    Local $hTlb = ControlGetHandle($hTrayWnd, "", "ToolbarWindow323")
    Local $hBtn = ControlGetHandle($hTrayWnd, "", "Button2")
    Local $aPos = ControlGetPos($hTrayWnd, "", $hBtn)
    Local $aTPos = ControlGetPos($hTrayWnd, "", $hTlb)
    For $i = ($aPos[0] - 1) + ($aPos[2] / 2) To $aPos[0] + $aPos[2] + $aTPos[2] Step $aPos[2]
        MouseMove($i, @DesktopHeight - 3, 1)
;~      ConsoleWrite("$i=" & $i & @CRLF)
;~      Sleep(10)
    Next
    MouseMove($aStartPos[0], $aStartPos[1], 1)
EndFunc   ;==>ShellTrayRefresh

 

as well as the link ITaskbarList4 interface

 

Please, every comment is appreciated!
leave your comments and experiences here!
Thank you very much  :)

Edited by ioa747
Update to Version: 2.0

I know that I know nothing

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...