Sign in to follow this  
Followers 0
JohnSAutoIt

Read full Tray Icon name from partial name

10 posts in this topic

Tray icons often carry more information than the process name. I want to be able to go to a tray icon using a partial name and read back the full text title of the icon (what is visible in the tooltip).

Share this post


Link to post
Share on other sites



JohnSAutoIt,

Welcome to the AutoIt forum. :D

When you post here it always helps if you have had a go at solving your problems beforehand. Having some code to work on is a great help - and no-one here is too keen to help the "code it for me" brigade.

But as I have the code to hand and am feeling generous tonight - here you go: :

; The script is not foolproof - I have found that using the first word/words of the tooltip text gives the best results.

#Include <GuiToolBar.au3>

Global $sToolTipTitle = "" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here

Global $iSystray_IconText = Get_Systray_IconText($sToolTipTitle)

If @Error Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    MsgBox(0,"Found", $iSystray_IconText)
EndIf

Exit

;............

Func Get_Systray_IconText($sToolTipTitle)

    ; Find systray handle
    Local $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for wanted tooltip
    Local $iSystray_ButtonNumber
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)
        If StringInStr($sText, $sToolTipTitle) = 1 Then Return $sText
    Next

    Return SetError(1, 0, "")

EndFunc

If anything is unclear, please ask. :huggles:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks for the code. I wasn't expecting anyone to do it, I was looking for pointers. Having exhausted all the Tray commands I eventually found that the tray was basically a toolbar. I ended up in the area of your code, perhaps not as bullet-proof. I got results but have some buttons that can't be found whatever is entered as a partial. Investigating.

Share this post


Link to post
Share on other sites

JohnSAutoIt,

Sorry if I came across as tetchy, it was the "I want" in the original post that had that effect! :huggles:

What is the text you are looking for in the traytip? And what "snippet" does not find the full text? I did warn that the code is not foolproof, but it usually works. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

You could try some functions from my UDF here: http://www.autoitscript.com/forum/index.php?showtopic=103871

Not sure if your results would be any different from Melba23's example though.

Share this post


Link to post
Share on other sites

The script only works with the first part of the string as the search string. To be more generic:

If StringInStr($sText, $sToolTipTitle) = 1 Then Return $sText

should be

If StringInStr($sText, $sToolTipTitle) > 0 Then Return $sText

I guess it depends what you are after. The "start of string only" may be a bit safer in getting the correct button with short search strings.

Share this post


Link to post
Share on other sites

JohnSAutoIt,

Thank you for that - it explains the "I have found that using the first word/words of the tooltip text gives the best results" comment I added.

I do not know how many times I have looked at that snippet and wondered why it was not working as I wanted it. Just takes another pair of eyes - peer review is a wonderful thing! :huggles:

Thank you again - I hope I helped you as much as you have just helped me! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

It had me fooled at first. You get so used to seeing 1=success 0=fail.

Share this post


Link to post
Share on other sites

Func Get_Systray_IconText($sToolTipTitle)

I went through docs and Google searches until I was getting bleary-eyed, then finally found your solution.

This works great! The only way to get status from one of our security apps at the office is from the tray icon text. Your solution gave me the means I needed. Big thanks! :idea:

Share this post


Link to post
Share on other sites

willichan,

Glad I could help - even if I did not realise it at the time. :idea:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0