Jump to content

Read full Tray Icon name from partial name


JohnSAutoIt
 Share

Recommended Posts

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • 3 months later...

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:

Link to comment
Share on other sites

  • Moderators

willichan,

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...