Code : Tout sélectionner
#include <GuiToolbar.au3>
#include <WinAPI.au3>
#NoTrayIcon
_SysTray_ClickItem("WinVNC", "right", 1) ; Infos à modifier
If @error Then MsgBox(48, "Failure", "Required item not found")
;=========# _SysTray_ClickItem #======================================================
;
;Function Name: _SysTray_ClickItem()
;Description: Click on item in Windows system tray by any substring in the title
;Parameters: $iTitle - The title of the item in Windows system tray (you can see the title of the item when mouse cursor hovered on item).
; $iButton - [optional] The button to click, "left" or "right". Default is the left button.
; $iClick - [optional] The number of times to click the mouse. Default is 1
; $sMove = [optional] True = Mouse will be moved, False (default) = Mouse will not be moved
; $iSpeed = [optional] Mouse movement speed
;Return Value(s): Success - Returns 1
; Failure - Returns 0 and sets @error to 1 if required item not found
;Requirement(s): AutoIt 3.2.10.0 and above
;Autor(s): R.Gilman (a.k.a rasim); Siao (Thanks for idea)
;
;====================================================================================
Func _SysTray_ClickItem($iTitle, $iButton = "left", $iClick = 1, $sMove = False, $iSpeed = 1)
Local $hToolbar, $iButCount, $aRect, $hButton, $cID, $i
$hToolbar = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
If @error Then
Return SetError(1, 0, 0)
EndIf
$iButCount = _GUICtrlToolbar_ButtonCount($hToolbar)
If $iButCount = 0 Then
Return SetError(1, 0, 0)
EndIf
$hButton = ControlGetHandle("[Class:Shell_TrayWnd]", "", "Button2")
If $hButton <> "" Then ControlClick("[Class:Shell_TrayWnd]", "", "Button2")
For $i = 0 To $iButCount - 1
$cID = _GUICtrlToolbar_IndexToCommand($hToolBar, $i)
If StringInStr(_GUICtrlToolbar_GetButtonText($hToolBar, $cID), $iTitle) Then
_GUICtrlToolbar_ClickButton($hToolbar, $cID, $iButton, $sMove, $iClick, $iSpeed)
Return 1
EndIf
Next
Return SetError(1, 0, 0)
EndFunc
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlToolbar_ClickAccel
; Description ...: Clicks a specific button using it's accelerator
; Syntax.........: _GUICtrlToolbar_ClickAccel($hWnd, $cAccel[, $sButton = "left"[, $fMove = False[, $iClicks = 1[, $iSpeed = 1]]]])
; Parameters ....: $hWnd - Handle to the control
; $cAccel - Button accelerator
; $sButton - Button to click
; $fMove - Mouse movement flag:
; | True - Mouse will be moved
; |False - Mouse will not be moved
; $iClicks - Number of clicks
; $iSpeed - Mouse movement speed
; Return values .:
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......:
; Related .......: _GUICtrlToolbar_ClickButton, _GUICtrlToolbar_ClickIndex
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _GUICtrlToolbar_ClickAccel($hWnd, $cAccel, $sButton = "left", $fMove = False, $iClicks = 1, $iSpeed = 1)
If $Debug_TB Then _GUICtrlToolbar_ValidateClassName($hWnd)
Local $iID
$iID = _GUICtrlToolbar_MapAccelerator($hWnd, $cAccel)
_GUICtrlToolbar_ClickButton($hWnd, $iID, $sButton, $fMove, $iClicks, $iSpeed)
EndFunc ;==>_GUICtrlToolbar_ClickAccel
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlToolbar_ClickButton
; Description ...: Clicks a specific button
; Syntax.........: _GUICtrlToolbar_ClickButton($hWnd, $iCommandID[, $sButton = "left"[, $fMove = False[, $iClicks = 1[, $iSpeed = 1]]]])
; Parameters ....: $hWnd - Handle to the control
; $iCommandID - Button command ID
; $sButton - Button to click
; $fMove - Mouse movement flag:
; | True - Mouse will be moved
; |False - Mouse will not be moved
; $iClicks - Number of clicks
; $iSpeed - Mouse movement speed
; Return values .:
; Author ........: Paul Campbell (PaulIA)
; Modified.......: Gary Frost
; Remarks .......:
; Related .......: _GUICtrlToolbar_ClickAccel, _GUICtrlToolbar_ClickIndex
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _GUICtrlToolbar_ClickButton($hWnd, $iCommandID, $sButton = "left", $fMove = False, $iClicks = 1, $iSpeed = 1)
If $Debug_TB Then _GUICtrlToolbar_ValidateClassName($hWnd)
Local $tPoint, $tRect, $iX, $iY, $iMode, $aPos
$tRect = _GUICtrlToolbar_GetButtonRectEx($hWnd, $iCommandID)
$tPoint = _WinAPI_PointFromRect($tRect)
$tPoint = _WinAPI_ClientToScreen($hWnd, $tPoint)
_WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
If Not $fMove Then
$iMode = Opt("MouseCoordMode", 1)
$aPos = MouseGetPos()
Opt("MouseCoordMode", $iMode)
_WinAPI_ShowCursor(False)
MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
MouseMove($aPos[0], $aPos[1], 0)
_WinAPI_ShowCursor(True)
Else
MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
EndIf
EndFunc ;==>_GUICtrlToolbar_ClickButton
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlToolbar_ClickIndex
; Description ...: Clicks a specific button using it's index
; Syntax.........: _GUICtrlToolbar_ClickIndex($hWnd, $iIndex[, $sButton = "left"[, $fMove = False[, $iClicks = 1[, $iSpeed = 1]]]])
; Parameters ....: $hWnd - Handle to the control
; $iIndex - Button index
; $sButton - Button to click
; $fMove - Mouse movement flag:
; | True - Mouse will be moved
; |False - Mouse will not be moved
; $iClicks - Number of clicks
; $iSpeed - Mouse movement speed
; Return values .:
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......:
; Related .......: _GUICtrlToolbar_ClickAccel, _GUICtrlToolbar_ClickButton
; Link ..........;
; Example .......; Yes
; ===============================================================================================================================
Func _GUICtrlToolbar_ClickIndex($hWnd, $iIndex, $sButton = "left", $fMove = False, $iClicks = 1, $iSpeed = 1)
If $Debug_TB Then _GUICtrlToolbar_ValidateClassName($hWnd)
Local $iCommandID
$iCommandID = _GUICtrlToolbar_IndexToCommand($hWnd, $iIndex)
_GUICtrlToolbar_ClickButton($hWnd, $iCommandID, $sButton, $fMove, $iClicks, $iSpeed)
EndFunc ;==>_GUICtrlToolbar_ClickIndex
; #FUNCTION# ====================================================================================================
; Description ...: Returns the top/left coordinates of a tagRECT as a tagPOINT structure
; Parameters ....: $tRect - tagRECT structure
; $fCenter - If True, the return will be a point at the center of the rectangle, otherwise the left/top
; +coordinates are returned.
; Return values .: Success - tagPOINT structure
; Author ........: Paul Campbell (PaulIA)
; Remarks .......: This function is used to get the click position for many of the click functions in the library
; Related .......:
; ====================================================================================================
Func _WinAPI_PointFromRect(ByRef $tRect, $fCenter = True)
Local $iX1, $iY1, $iX2, $iY2, $tPoint
$iX1 = DllStructGetData($tRect, "Left")
$iY1 = DllStructGetData($tRect, "Top")
$iX2 = DllStructGetData($tRect, "Right")
$iY2 = DllStructGetData($tRect, "Bottom")
If $fCenter Then
$iX1 = $iX1 + (($iX2 - $iX1) / 2)
$iY1 = $iY1 + (($iY2 - $iY1) / 2)
EndIf
$tPoint = DllStructCreate($tagPOINT)
DllStructSetData($tPoint, "X", $iX1)
DllStructSetData($tPoint, "Y", $iY1)
Return $tPoint
EndFunc ;==>_WinAPI_PointFromRect
; #FUNCTION# ====================================================================================================
; Description ...: Returns the X/Y values from a tagPOINT structure
; Parameters ....: $tPoint - tagPOINT structure
; $iX - X value
; $iY - Y value
; Return values .:
; Author ........: Paul Campbell (PaulIA)
; Remarks .......: This function extracts the X/Y values from a tagPOINT structure
; Related .......: _Lib_GetPointFromXY, _Lib_GetXYFromRect
; ====================================================================================================
Func _WinAPI_GetXYFromPoint(ByRef $tPoint, ByRef $iX, ByRef $iY)
$iX = DllStructGetData($tPoint, "X")
$iY = DllStructGetData($tPoint, "Y")
EndFunc ;==>_WinAPI_GetXYFromPoint