Jump to content

Hidden Tray Icon Text


Recommended Posts

Hi friends,

 

Is there any way to get the text of hidden items in a system tray and to click on the hidden icon?

 

The following code gets text of all visible items but I want to get the text of the hidden icons too.

 

Please help. 

 

Pooja.

#include <GuiToolBar.au3>
 
$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
If @error Then
Msgbox(0, "Error", "Couldn't get the Tray handle")
Exit
EndIf
; Get systray item count
Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) ;get button count
If $iSystray_ButCount = 0 Then
Msgbox(0, "Error", "No tray icons")
Exit
EndIf    ; Look for wanted tooltip
$sTrayicons = $iSystray_ButCount & " Tray Icons are: " & @CRLF
For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 
$sTrayicons = $sTrayicons & _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber) & @CRLF
Next
 
Msgbox(0, "Tray icons", $sTrayicons)
Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

PoojaKrishna,

You can always get the hideen icons to display as I show here. :)

M23

P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)

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

Hi,

Thanks M23 but it does not work on my machine for hidden icons. Actually I'm trying to click on the TeamViewer icon on my machine. It works fine if the icon is active on the tray bar. Mine is a Win 7 machine.

It returns the following message for hidden icon.

---------------------------

Error
---------------------------
Icon not found in system tray
---------------------------
OK   
---------------------------
Edited by PoojaKrishna
Link to comment
Share on other sites

  • Moderators

PoojaKrishna,

Have you checked the CLASS/INSTANCE values for the "show hidden icons" button as suggested in the post to which I linked? If they are not the same on Win7 then it is not surprising that the code does not work. ;)

Use the AutoIt Window Info tool and see what you get as a return. :)

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

Yes, they are the same as in your code. Plesae see the following information i have copied from the Info tool.

>>>> Window <<<<
Title:
Class: Shell_TrayWnd
Position: 0, 734
Size: 1024, 34
Style: 0x96000000
ExStyle: 0x00000088
Handle: 0x0000000000010068
 
>>>> Control <<<<
Class: Button
Instance: 1
ClassnameNN: Button1
Name:
Advanced (Class): [CLASS:Button; INSTANCE:1]
Link to comment
Share on other sites

  • Moderators

PoojaKrishna,

Do the hidden icons display when you ControlClick on the button? :huh:

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

Please see the code added below. Edited for TeamViewer. It clicks on the show button but couldn't get the TeamViewer icon.

#include <GuiToolBar.au3>
Global $hSysTray_Handle

_Show()

Func _Show()
    
    $hTaskBarHandle = WinGetHandle("[Class:Shell_TrayWnd]", "")
    ControlClick($hTaskBarHandle, "", "[CLASS:Button; INSTANCE:1]")
    sleep(1000)
    
    $iSysTray_ButtonNumber = _Get_Systray_Index("TeamViewer") ; Put your traytip text here as before <<<<<<<<<<<<<<<<<<<<<<
    If @error Then
        MsgBox(16, "Error", "Icon not found in system tray")
        Exit
    EndIf
    ; Action icon <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSysTray_ButtonNumber, "right")


EndFunc   ;==>_Show

Func _Get_Systray_Index($sText)

    ; Find systray handle
    $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  tooltip
    For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber), $sText) > 0 Then ExitLoop
    Next

    If $iSysTray_ButtonNumber = $iSysTray_ButCount Then
        Return SetError(1, 0, -1) ; Not found
    Else
        Return $iSysTray_ButtonNumber ; Found
    EndIf

EndFunc   ;==>Get_SysTray_Index
Link to comment
Share on other sites

  • Moderators

PoojaKrishna,

You do not get the text of any of the icons? :huh:

Do you at least get the icon count returned? :huh:

M23

Edited by Melba23
Added question

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

  • Moderators

PoojaKrishna,

So the hidden icons are in a pop up window and not in the systray - hardly surprising that they do not get recognised by the code. ;)

Let us see if we can recognise the pop up:

#include <WinAPI.au3>

$hTaskBarHandle = WinGetHandle("[Class:Shell_TrayWnd]", "")
ControlClick($hTaskBarHandle, "", "[CLASS:Button; INSTANCE:1]")

; You may need to adjust this
Sleep(1000)

; Run this once the popup has appeared
$aPopUp_List = _WinAPI_EnumWindowsPopup()
If IsArray($aPopUp_List Then
    _ArrayDisplay($aPopUp_List, "Pop up list")
Else
    MsgBox(16, "Error", "Non-standard Pop-up")
EndIf
What do you get in the array (if indeed you get one)? :huh:

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

Melba, starting from this i'm sure you can find a better way:

; johnmcloud - 2014
#include <GuiToolBar.au3>

Global $vIsHidden

$vIsHidden = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray")
If $vIsHidden == 1 Then
    Run("rundll32.exe shell32.dll Options_RunDLL 5")
    WinWait("[CLASS:CabinetWClass]", "")
    ControlClick("[CLASS:CabinetWClass]", "", "[CLASS:Button; INSTANCE:3]")
    ControlClick("[CLASS:CabinetWClass]", "", "[CLASS:Button; INSTANCE:1]")
EndIf

$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
If @error Then
    MsgBox(0, "Error", "Couldn't get the Tray handle")
    Exit
EndIf

Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) ;get button count
If $iSystray_ButCount = 0 Then
    MsgBox(0, "Error", "No tray icons")
    Exit
EndIf

MsgBox(0, "Tray icons", $iSystray_ButCount)

If $vIsHidden == 1 Then
    Run("rundll32.exe shell32.dll Options_RunDLL 5")
    WinWait("[CLASS:CabinetWClass]", "")
    ControlClick("[CLASS:CabinetWClass]", "", "[CLASS:Button; INSTANCE:3]")
    ControlClick("[CLASS:CabinetWClass]", "", "[CLASS:Button; INSTANCE:1]")
EndIf

The EnableAutoTray show-hide all icon in the traybar, the problem is i don't have found any way to refresh Explorer without closing it, envupdate, some _SendMessage etc. but nothing work so i have used the ControlClick way in the GUI

Edited by johnmcloud
Link to comment
Share on other sites

Hi Melba,

Sorry, it couldn't find any popup windows. The following code returns the count as 0. An edited version of your code.

#include <WinAPI.au3>
#include<Array.au3>

$hTaskBarHandle = WinGetHandle("[Class:Shell_TrayWnd]", "")
ControlClick($hTaskBarHandle, "", "[CLASS:Button; INSTANCE:1]")

; You may need to adjust this
Sleep(5000)

; Run this once the popup has appeared
$aWindows = _WinAPI_EnumWindowsPopup()
msgbox(0,"", $aWindows[0][0])
    For $i = 1 To $aWindows[0][0]
        $text = "Window Handle: " & $aWindows[$i][0] & @LF
        $text &= "Window Class: " & $aWindows[$i][1] & @LF
        $text &= "Window Title: " & WinGetTitle($aWindows[$i][0]) & @LF
        $text &= "Window Text: " & WinGetText($aWindows[$i][0]) & @LF
        $text &= "Window Process: " & WinGetProcess($aWindows[$i][0])
        MsgBox(0, "Item " & $i & " of " & $aWindows[0][0], $text)
    Next

Yes John I was also planning something like you have posted but I too see no way to refresh the tray after a reg edit.

Edited by PoojaKrishna
Link to comment
Share on other sites

PoojaKrishna,

My script work because don't write directly in the registry but use the "window" version, did you try it? If there is a way to refresh the tray after the regedit you can only use that way

Edited by johnmcloud
Link to comment
Share on other sites

John,

Your script is working on my machine with some small changes. Thank you so much for your help. I'm planning to add your way until I get a direct way to refresh the tray.

; johnmcloud - 2014
#include <GuiToolBar.au3>
#RequireAdmin
Global $vIsHidden

$vIsHidden = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer", "EnableAutoTray")
If $vIsHidden == 1 Then
    Run("rundll32.exe shell32.dll Options_RunDLL 5")
    WinWait("Notification Area Icons", "")
sleep(500)
    ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:3]")
sleep(500)

    ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:1]")
sleep(500)

EndIf

$hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
If @error Then
    MsgBox(0, "Error", "Couldn't get the Tray handle")
    Exit
EndIf

Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) ;get button count
If $iSystray_ButCount = 0 Then
    MsgBox(0, "Error", "No tray icons")
    Exit
EndIf

MsgBox(0, "Tray icons", $iSystray_ButCount)

If $vIsHidden == 1 Then
    Run("rundll32.exe shell32.dll Options_RunDLL 5")
    WinWait("Notification Area Icons", "")
sleep(500)
    ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:3]")
sleep(500)

    ControlClick("Notification Area Icons", "", "[CLASS:Button; INSTANCE:1]")
sleep(500)
EndIf
Edited by PoojaKrishna
Link to comment
Share on other sites

Hi friends,

We can close the explorer after the reg edits and it will auto start again with the new changes. Please see the following code. Working for me.

#requireadmin
Global $vIsHidden ;Reg value of show all tray icons
Global $sKey
 If @OSArch = "X64" Then
    sKey = "HKEY_CURRENT_USER64\Software\Microsoft\Windows\CurrentVersion\Explorer"
Else
   $sKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer"
EndIf
$vIsHidden = RegRead($sKey, "EnableAutoTray")
If @error Then
   Msgbox(0,"Error", "Couldn't read the regkey with error: " & @error)
   Exit
EndIf

Msgbox(0,"EnableAutoTray","Value at Reg: " & $vIsHidden)
If $vIsHidden = 1 Then ;If tray has hidden icons
   RegWrite ($sKey , "EnableAutoTray", "REG_DWORD", "0" )
   If @error Then
   Msgbox(0,"Error", "Couldn't write the regkey with error: " & @error)
   Exit
EndIf
   sleep(1000)
   $PID = ProcessExists("explorer.exe") ; Will return the PID or 0 if the process isn't found.
   If $PID Then ProcessClose($PID)
      sleep(1000)
EndIf
Link to comment
Share on other sites

PoojaKrishna:

The EnableAutoTray show-hide all icon in the traybar, the problem is i don't have found any way to refresh Explorer without closing it, envupdate, some _SendMessage etc. but nothing work so i have used the ControlClick way in the GUI

 

 

Close-reopen Explorer.exe is obvious that works ;)

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

×
×
  • Create New...