tuape Posted July 18, 2005 Share Posted July 18, 2005 (edited) Inspired by this thread: Hide icon of a running program, Hide iconAn udf to get process behind any systray icon for easier closing and to give ability to remove any icon(s) from systray.Functions:;=============================================================================== ; ; Function Name: _SysTrayIconTitles() ; Description: Get list of all window titles that have systray icon ; Parameter(s): None ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns an array with all window titles ; On Failure - TO BE DONE ; Author(s): Tuape ; ;===============================================================================;=============================================================================== ; ; Function Name: _SysTrayIconProcesses() ; Description: Get list of all process' names that have systray icon ; Parameter(s): None ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns an array with all process names ; On Failure - TO BE DONE ; Author(s): Tuape ; ;===============================================================================;=============================================================================== ; ; Function Name: _SysTrayIconPids() ; Description: Get list of all processes id's that have systray icon ; Parameter(s): None ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns an array with all process id's ; On Failure - TO BE DONE ; Author(s): Tuape ; ;===============================================================================;=============================================================================== ; ; Function Name: _SysTrayIconIndex($name, $mode=0) ; Description: Get list of all processes id's that have systray icon ; Parameter(s): $name = process name / window title text ; $mode 0 = get index by process name (default) ; 1 = get index by window title ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns index of found icon ; On Failure - Returns -1 if icon for given process/wintitle ; was not found. ; - Sets error to 1 and returns -1 in case of bad ; arguments ; Author(s): Tuape ; ;===============================================================================;=============================================================================== ; ; Function Name: _SysTrayIconCount ; Description: Utility function. Returns number of icons on systray ; Note: Hidden icons are also reported ; Parameter(s): None ; ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns number of icons found ; On Failure - TO BE DONE ; ; Author(s): Tuape ; ;===============================================================================;=============================================================================== ; ; Function Name: _SysTrayIconRemove($index=0 ; Description: Removes systray icon completely. ; ; Parameter(s): index = icon index. Can be queried with _SysTrayIconIndex() ; Default = 0 ; ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns 1 if icon successfully removed ; On Failure - Sets error to 1 and returns -1 ; ; Author(s): Tuape ; ;===============================================================================;=============================================================================== ; ; Function Name: _SysTrayIconVisible($flag, $index) ; Description: Hides / unhides any icon on systray ; ; Parameter(s): $flag = hide (1) or show (0) icon ; $index = icon index. Can be queried with _SysTrayIconIndex() ; ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns 1 if operation was successfull / 0 if ; icon was already hidden/unhidden ; On Failure - If invalid parameters, returns -1 and sets error ; to 1 ; ; Author(s): Tuape ; ;===============================================================================;=============================================================================== ; ; Function Name: _SysTrayIconmove($curPos, $newPos) ; Description: Moves systray icon ; ; Parameter(s): $curPos = icon's current index (0 based) ; $newPos = icon's new position ; ----> ($curPos+1 = one step to right, $curPos-1 = one step to left) ; ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns 1 if operation was successful ; On Failure - If invalid parameters, returns -1 and sets error ; to 1 ; ; Author(s): Tuape ; ;===============================================================================;=============================================================================== ; ; Function Name: _SysTrayIconPos($iIndex=0) ; Description: Gets x & y position of systray icon ; Parameter(s): $iIndex = icon index (Note: starting from 0) ; ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns x [0] and y [1] position of icon ; On Failure - Returns -1 if icon is hidden (Autohide on XP etc.) ; Sets error to 1 if some internal error happens ; ; Author(s): Tuape ; ;=============================================================================== ;=============================================================================== ; ; Function Name: _SysTrayIconTooltip($iIndex=0) ; Description: Utility function. Gets the tooltip text of ; systray icon of given index ; Parameter(s): $iIndex = icon index (Note: starting from 0) ; ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns tooltip text of icon ; On Failure - Returns -1 in error situations ; ; Author(s): Tuape ; ;===============================================================================As you see better error handling needs to be added.I hope someone with more experience with Win32API, DllCalls & structures can take a look at this; just to make sure it's not leaking memory etc.All comments welcome. Please also suggest functions you would like to add to this. I am already planning to add _SysTrayIconHide / unhide.Some examples:expandcollapse popup#include "SysTray_UDF.au3" ; -- Example 1 -- ; Get window titles of all windows that have icon on systray $iTitles = _SysTrayIconTitles() ; Get process names of all processes that have icon on systray $iProcesses = _SysTrayIconProcesses() For $i=0 to Ubound($iTitles)-1 ; write the info to consolewindow ConsoleWrite(@CR & "#" &$i & "Title: " & $iTitles[$i] & ", process: " & $iProcesses[$i]) Next ; -- Example 2 -- $st_process = "SETI@home.exe"; change this if needed _SysTrayIconRemove(_SysTrayIconIndex($st_process)) ; Note that only the icon was removed; process still should be running ; -- Example 3 -- $st_process = "winampa.exe"; change this if needed _SysTrayIconVisible(1, _SysTrayIconIndex($st_process)) ; Note that the icon is hidden Sleep(10000) _SysTrayIconVisible(0, _SysTrayIconIndex($st_process)) ; -- Example 4 -- $pos = _SysTrayIconIndex($st_process) $ret = _SysTrayIconmove($pos, $pos+3); edit newpos if needed ; -- Example 5 -- ; Left-click Outlook's icon on system tray ; Press hide inactive icon's button part is from Valik's refresh system tray script! $oldMatchMode = Opt("WinTitleMatchMode", 4) $oldChildMode = Opt("WinSearchChildren", 1) $class = "classname=Shell_TrayWnd" $hControl = ControlGetHandle($class, "", "Button2") ; get tray position and move there. Helps if Auto Hide tray option is used. $posTray = WinGetPos(_FindTrayToolbarWindow()) MouseMove($posTray[0], $posTray[1]) ; If XP and the Hide Inactive Icons mode is active If $hControl <> "" And ControlCommand($class, "", $hControl, "IsVisible","") Then ControlClick($class, "", $hControl) Sleep(250); Small delay to allow the icons to be drawn EndIf $index = _SysTrayIconIndex("Outlook.exe"); Change this to some other application if needed If $index <> -1 Then $pos = _SysTrayIconPos($index) If $pos = -1 Then Exit MouseMove($pos[0], $pos[1]) Sleep(1000) MouseClick("left") EndIf ConsoleWrite(@CRLF & @CRLF & "Pos[0]: " & $pos[0] & "$pos[1]: " & $pos[1]) ; Restore Opt settings Opt("WinTitleMatchMode", $oldMatchMode) Opt("WinSearchChildren", $oldChildMode) ; -- Example 6 - get all tooltip texts -- For $p = 0 to _SystrayIconCount() MsgBox(0, "Tooltip", _SysTrayIconTooltip($p)) Next ; -- Example 7 - get tooltip text when process name is known -- MsgBox(0, "Tooltip", _SysTrayIconTooltip(_SysTrayIconIndex("Feedreader.exe")))Note: This UDF has been tested with winXP only. Might work with win2000 but doesn't work in win98 AFAIKEdit: Added _SysTrayIconVisible and an example how to use it.Edit: Added _SysTrayIconmove and an example how to use it.Edit: Added _SysTrayIconPos and an example how to use it for clicking specific icon.Edit: New hWnd handling functions broke this (hWnd(), IsHwnd(). Updated the attachment, now needs 3.1.1.66 Edit: Added function to get tooltip texts + added an example how to use thisEdit: Changed all int_ptr to int* formatEdit: Corrected all memory leaks caused by incorrect parameter in VirtualFreeExSystray_test.au3SysTray_UDF.au3 Edited January 19, 2008 by tuape Link to comment Share on other sites More sharing options...
w0uter Posted July 18, 2005 Share Posted July 18, 2005 what if i want one back My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
tuape Posted July 18, 2005 Author Share Posted July 18, 2005 what if i want one back <{POST_SNAPBACK}>You have to stop and restart the process owning that systray icon. There is a message TB_HIDEBUTTONTB_HIDEBUTTON MessageHides or shows the specified button in a toolbar.But I haven't really looked at it yet. I think that can be used for _SysTrayIconHide Link to comment Share on other sites More sharing options...
Ejoc Posted July 18, 2005 Share Posted July 18, 2005 (edited) In the functions where you are using DllStructCreate() when you have errors and return -1, before the return call DllStructDelete()'s on the structs. Other then that and I personally check for errors after each DllStructCreate() but alot of people don't. Example: $procHandle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $PROCESS_ALL_ACCESS, 'int', False, 'int', $pId) If @error Then ConsoleWrite("Error: Could not read toolbar process memory, " & @error) DllStructDelete($TBBUTTON);add DllStructDelete($TBBUTTON2);add DllStructDelete($ExtraData);add return -1 EndIf Edited July 18, 2005 by Ejoc Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs Link to comment Share on other sites More sharing options...
buzz44 Posted July 18, 2005 Share Posted July 18, 2005 Should... Const $PROCESS_ALL_ACCESS = 2035711 be... Const $PROCESS_ALL_ACCESS = 16533; 0xFFF qq Link to comment Share on other sites More sharing options...
w0uter Posted July 18, 2005 Share Posted July 18, 2005 (edited) Should...Const $PROCESS_ALL_ACCESS = 2035711be...Const $PROCESS_ALL_ACCESS = 16533; 0xFFF<{POST_SNAPBACK}>PROCESS_ALL_ACCESS ISNT 0XFFF. its 0x1f0fff (2035711). just google "const PROCESS_ALL_ACCESS" Edited July 18, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
buzz44 Posted July 18, 2005 Share Posted July 18, 2005 (edited) All references I can find for PROCESS_ALL_ACCESS = 0x1F0FFF are dated prior to 2005, I have found one or two that say it is = to 0xFFF dated this year. I got my original value (0xFFF) from APIViewer 2004 (Released 15/2/2004). Edited July 18, 2005 by Burrup qq Link to comment Share on other sites More sharing options...
w0uter Posted July 18, 2005 Share Posted July 18, 2005 (edited) acording from the files that come with the beta Dev-C++ (Feb 22, 2005 08:38) Process_all_access = 2035711 Edited July 18, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
tuape Posted July 18, 2005 Author Share Posted July 18, 2005 In the functions where you are using DllStructCreate() when you have errors and return -1, before the return call DllStructDelete()'s on the structs. Other then that and I personally check for errors after each DllStructCreate() but alot of people don't.Example:$procHandle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $PROCESS_ALL_ACCESS, 'int', False, 'int', $pId) If @error Then ConsoleWrite("Error: Could not read toolbar process memory, " & @error) DllStructDelete($TBBUTTON);add DllStructDelete($TBBUTTON2);add DllStructDelete($ExtraData);add return -1 EndIf<{POST_SNAPBACK}>Of course, otherwise DllStructDelete's would not be called at all. Thanks! I will edit the attachment in first post. Link to comment Share on other sites More sharing options...
tuape Posted July 18, 2005 Author Share Posted July 18, 2005 Added _SysTrayIconmove which let's you change icon's position. See the first post. Link to comment Share on other sites More sharing options...
buzz44 Posted July 19, 2005 Share Posted July 19, 2005 @Larry Thanks for clarification, where did you get this value btw? @tuape Nice, I haven't had time to look at it yet but I will be sure to when I get home. qq Link to comment Share on other sites More sharing options...
tuape Posted August 5, 2005 Author Share Posted August 5, 2005 *Bump* Added function to get icon's position and example how to use it for clicking specific icon. Link to comment Share on other sites More sharing options...
tuape Posted August 5, 2005 Author Share Posted August 5, 2005 *Bump*Added function to get icon's position and example how to use it for clicking specific icon.<{POST_SNAPBACK}>Could somebody please try this out? I only have WinXP and I would like to know if it works in Win2000.Question "how to click icon in system tray" has been asked frequently, but when there's a solution nobody is interested Link to comment Share on other sites More sharing options...
BigDod Posted August 5, 2005 Share Posted August 5, 2005 (edited) Could somebody please try this out? I only have WinXP and I would like to know if it works in Win2000.Question "how to click icon in system tray" has been asked frequently, but when there's a solution nobody is interested <{POST_SNAPBACK}>I am trying to incorporate this into a script but get the followin errorC:\Program Files\AutoIt3\Include\SysTray_UDF.au3 (225) : ==> Unknown function name.:$TBBUTTON = DllStructCreate($str) $TBBUTTON = ^ ERROR>AutoIT3.exe ended.>Exit code: 0  Time: 0.849I am using the release version of AutoIT could this be the problem.BTWI am using XP as well Edited August 5, 2005 by BigDod Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
tuape Posted August 5, 2005 Author Share Posted August 5, 2005 I am trying to incorporate this into a script but get the followin errorI am using the release version of AutoIT could this be the problem.BTWI am using XP as well<{POST_SNAPBACK}>You need the beta version of AutoIt. Download it from here Link to comment Share on other sites More sharing options...
GaryFrost Posted August 5, 2005 Share Posted August 5, 2005 yep, need beta SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
BigDod Posted August 5, 2005 Share Posted August 5, 2005 You need the beta version of AutoIt. Download it from here<{POST_SNAPBACK}>Downloaded latest Beta and it worked a treat for my application.Many Thanks Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
tuape Posted August 5, 2005 Author Share Posted August 5, 2005 Downloaded latest Beta and it worked a treat for my application.Many Thanks  <{POST_SNAPBACK}>That's good to hear. Thanks for trying it out. Link to comment Share on other sites More sharing options...
this-is-me Posted September 29, 2005 Share Posted September 29, 2005 (edited) @tuape, I have need of the tooltip of a tray icon instead of just the window title owning it. This single window has multiple icons, and I need the text in the tooltip of the icon. Do you have any ideas? EDIT: I got this far, but I am unsure whether the function needs the hwnd of the tray or the hwnd of the icon. $index = 0 $bufferptr = DllStructCreate ("ptr") $lResult = DLLCall("user32.dll","int","SendMessage", "hwnd", _FindTrayToolbarWindow(), "int", $TB_GETBUTTONTEXT, "int", $index, "ptr", DllStructGetPtr($bufferptr)) $txt = DllStructGetData(DllStructCreate("char[" & $lResult[0] & "]", DllStructGetData($bufferptr, 1)), 1) MsgBox(0,"",$txt) Edited September 29, 2005 by this-is-me Who else would I be? Link to comment Share on other sites More sharing options...
quaizywabbit Posted September 29, 2005 Share Posted September 29, 2005 @tuape, I have need of the tooltip of a tray icon instead of just the window title owning it. This single window has multiple icons, and I need the text in the tooltip of the icon. Do you have any ideas?EDIT: I got this far, but I am unsure whether the function needs the hwnd of the tray or the hwnd of the icon.$index = 0$bufferptr = DllStructCreate ("ptr")$lResult = DLLCall("user32.dll","int","SendMessage", "hwnd", _FindTrayToolbarWindow(), "int", $TB_GETBUTTONTEXT, "int", $index, "ptr", DllStructGetPtr($bufferptr))$txt = DllStructGetData(DllStructCreate("char[" & $lResult[0] & "]", DllStructGetData($bufferptr, 1)), 1)MsgBox(0,"",$txt) the function in red should be a variable....... [u]Do more with pre-existing apps![/u]ANYGUIv2.8 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now