Advertisement
FichteFoll

AutoIt - ShellTray UDF

Sep 16th, 2011
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 6.04 KB | None | 0 0
  1. #include-once
  2.  
  3. #include <GuiToolBar.au3>
  4.  
  5. ; #INDEX# =======================================================================================================================
  6. ; Title .........: ShellTray UDF (1.1)
  7. ; Date ..........: 16.09.2011
  8. ; AutoIt Version : 3.3 + (development version = 3.3.6.0)
  9. ; Language ......: English
  10. ; Description ...: Some workarounds for GuiToolBar.au3 with the shell tray
  11. ; Remarks .......:
  12. ; Link ..........:
  13. ; Author ........: FichteFoll
  14. ;
  15. ; #CHANGELOG# ===================================================================================================================
  16. ; # 1.1 [16.09.2011]
  17. ;     - Added: Parameter for $fMove
  18. ;     - Added: Documentation
  19. ;
  20. ; #CURRENT# =====================================================================================================================
  21. ; _TrayTool_GetHandle              Retrieves the control handle for any other functions
  22. ; _TrayTool_ClickText              Enumerates all icons in tray from index and clicks the one that matches the regular expression
  23. ; _TrayTool_ClickIndex             See _GUICtrlToolbar_ClickIndex for equivalent
  24. ; _TrayTool_ClickButton            See _GUICtrlToolbar_ClickButton for equivalent
  25. ;
  26. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  27. ;
  28. ; #TODO# ========================================================================================================================
  29. ; - nothing?
  30. ; ===============================================================================================================================
  31.  
  32. ; ###############################################################################################################################
  33.  
  34.  
  35. ; #Function# ===========================================================================================================================================
  36. ; Name............: _TrayTool_GetHandle
  37. ; Description.....: Retrieves the control handle for any other functions
  38. ; Syntax..........: _TrayTool_GetHandle()
  39. ; Parameters......: None
  40. ; Return values ..:
  41. ;                     Success    - The control handle
  42. ;                     Failure    - 0 and @error = 1 if the control was not found
  43. ; Author .........: FichteFoll
  44. ; Modified........:
  45. ; Remarks ........:
  46. ; Related ........: ControlGetHandle
  47. ; Link ...........;
  48. ; Example ........; _TrayTool_ClickText(_TrayTool_GetHandle(), "^Skype", False, 2) ; double clicks the skype tray icon
  49. ; ======================================================================================================================================================
  50. Func _TrayTool_GetHandle()
  51.     Local $hwndTrayTool = ControlGetHandle("[CLASS:Shell_TrayWnd; INSTANCE:1]", "", "[CLASS:ToolbarWindow32; INSTANCE:1]")
  52.     If IsHWnd($hwndTrayTool) Then Return $hwndTrayTool
  53.     Return SetError(1, 0, 0)
  54. EndFunc
  55.  
  56. ; #Function# ===========================================================================================================================================
  57. ; Name............: _TrayTool_ClickText
  58. ; Description.....: Enumerates all icons in tray from index and clicks the one that matches the regular expression
  59. ; Syntax..........: _TrayTool_ClickText($hwndTrayTool, $sPattern, $sButton = "left", $iClicks = 1, $iSpeed = 1)
  60. ; Parameters......:
  61. ;                   $hwndTrayTool- Handle from _TrayTool_GetHandle()
  62. ;                   $sPattern    - A regular expression that matches the description of the icon to click
  63. ;                   $sButton     - [optional] The button with that the click should be performed
  64. ;                   $fMove       - [optional] If true the mouse will be moved
  65. ;                   $iClicks     - [optional] Number of clicks
  66. ;                   $iSpeed      - [optional] Mouse movement speed
  67. ; Return values ..:
  68. ;                     Success    - 1 if _GUICtrlToolbar_ClickButton is called, since this function does not have a return value
  69. ;                     Failure    - 0 and @error:
  70. ;                                        | 1 - $hwndTrayTool is not a handle
  71. ;                                        | 2 - Regular expression not found
  72. ; Author .........: FichteFoll
  73. ; Modified........:
  74. ; Remarks ........:
  75. ; Related ........: _GUICtrlToolbar_GetButtonText, _GUICtrlToolbar_ClickButton
  76. ; Link ...........;
  77. ; Example ........; _TrayTool_ClickText(_TrayTool_GetHandle(), "^Skype", False, 2) ; double clicks the skype tray icon
  78. ; ======================================================================================================================================================
  79. Func _TrayTool_ClickText($hwndTrayTool, $sPattern, $sButton = "left", $fMove = False, $iClicks = 1, $iSpeed = 1)
  80.     If Not IsHWnd($hwndTrayTool) Then Return SetError(1, 0, 0)
  81.     Local $iIndex = -1, $i = 0, $sBtnStringLast = '', $sBtnStringPreLast = ''
  82.  
  83.     Local $iCmdID =  _GUICtrlToolbar_IndexToCommand($hwndTrayTool, $i), $sBtnString = _GUICtrlToolbar_GetButtonText($hwndTrayTool, $iCmdID)
  84.     While $sBtnString <> $sBtnStringLast Or $sBtnStringLast <> $sBtnStringPreLast
  85.         If StringRegExp($sBtnString, $sPattern) Then Return _TrayTool_ClickButton($hwndTrayTool, $iCmdID, $sButton, $fMove, $iClicks, $iSpeed)
  86.         $sBtnStringPreLast = $sBtnStringLast
  87.         $sBtnStringLast = $sBtnString
  88.         $i += 1
  89.         $iCmdID =  _GUICtrlToolbar_IndexToCommand($hwndTrayTool, $i)
  90.         $sBtnString = _GUICtrlToolbar_GetButtonText($hwndTrayTool, $iCmdID)
  91.     WEnd
  92.  
  93.     Return SetError(2, 0, 0)
  94. EndFunc
  95.  
  96.  
  97. ; See _GUICtrlToolbar_ClickIndex for equivalent
  98. Func _TrayTool_ClickIndex($hwndTrayTool, $iIndex, $sButton = "left", $fMove = False, $iClicks = 1, $iSpeed = 1)
  99.     If Not IsHWnd($hwndTrayTool) Then Return SetError(1, 0, 0)
  100.     Return 1 + _GUICtrlToolbar_ClickIndex($hwndTrayTool, $iIndex, $sButton, $fMove, $iClicks, $iSpeed)
  101. EndFunc
  102.  
  103. ; See _GUICtrlToolbar_ClickButton for equivalent
  104. Func _TrayTool_ClickButton($hwndTrayTool, $iCmdID, $sButton = "left", $iClicks = 1, $iSpeed = 1)
  105.     If Not IsHWnd($hwndTrayTool) Then Return SetError(1, 0, 0)
  106.     Return 1 + _GUICtrlToolbar_ClickButton($hwndTrayTool, $iCmdID, $sButton, $fMove, $iClicks, $iSpeed)
  107. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement