[LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

Post your working scripts, libraries and tools for AHK v1.1 and older
Vince42
Posts: 6
Joined: 05 Feb 2016, 14:41

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

21 Nov 2017, 15:17

RiseUp wrote: If it appears in Task Manager as java.exe, then surely that could be the issue. Also, the uncommented call to the library function in your code simulates a single-click with the left mouse button. Is that what you're trying for?

Using TrayIcon_GetInfo() would definitely help to debug your issue, but it isn't necessary to get it working once you have the right parameter(s) figured out for TrayIcon_Button().
I already unsuccessfully tried "java.exe" als Parameter - obviously something is missing or they changed something in Windwos 10 again.

Yes, a single click with the left mouse button is exactly what I need.

Do you have a sample code to iterate over the icons in the TrayIcon?
RiseUp
Posts: 28
Joined: 01 Oct 2013, 21:27

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

21 Nov 2017, 16:13

Vince42 wrote:I already unsuccessfully tried "java.exe" als Parameter - obviously something is missing or they changed something in Windwos 10 again.

Yes, a single click with the left mouse button is exactly what I need.

Do you have a sample code to iterate over the icons in the TrayIcon?
Sure, try the following code. It should bring up a ListView with all of your system tray icons' process names, tooltips, and handles.

Code: Select all

#NoEnv							; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input					; Recommended for new scripts due to its superior speed and reliability.

; This script assumes that TrayIcon.ahk is in one of your library locations:
;    %A_ScriptDir%\Lib\                                  ; Local library - requires v1.0.90+.
;    %A_MyDocuments%\AutoHotkey\Lib\                     ; User library.
;    path-to-the-currently-running-AutoHotkey.exe\Lib\   ; Standard library.
; If not in any of those, then add an #Include at the top pointing to the file.

; Create a ListView to display the list of info gathered
Gui Add, ListView, Grid r30 w500 Sort, Process|Tooltip|Handle

; Get all of the icons in the system tray using Sean's TrayIcon library
oIcons := TrayIcon_GetInfo()

; Loop through the info we obtained and add it to the ListView
Loop, % oIcons.MaxIndex()
{
    proc := oIcons[A_Index].Process
    ttip := oIcons[A_Index].tooltip
    hWnd := oIcons[A_Index].hWnd
    
    LV_Add(, proc, ttip, hWnd)
}

LV_ModifyCol()

Gui Show, Center, System Tray Icons
Return

GuiEscape:
GuiClose:
    ExitApp
This works for me on Windows 10. Let me know if it works for you.
Vince42
Posts: 6
Joined: 05 Feb 2016, 14:41

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

23 Nov 2017, 16:11

Sorry for the late reply, I have not been notified of your reply. :(

Thank you very much for the code! I ran the script and five of twelve SysTray icons are listed - and the java one is missing amongst others. I guess that's the point, where my endeavour comes to an abrupt end?
Aenfa
Posts: 13
Joined: 15 May 2016, 18:06

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

24 Nov 2017, 16:12

RiseUp wrote:
Vince42 wrote:I already unsuccessfully tried "java.exe" als Parameter - obviously something is missing or they changed something in Windwos 10 again.

Yes, a single click with the left mouse button is exactly what I need.

Do you have a sample code to iterate over the icons in the TrayIcon?
Sure, try the following code. It should bring up a ListView with all of your system tray icons' process names, tooltips, and handles.

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

; This script assumes that TrayIcon.ahk is in one of your library locations:
; %A_ScriptDir%\Lib\ ; Local library - requires v1.0.90+.
; %A_MyDocuments%\AutoHotkey\Lib\ ; User library.
; path-to-the-currently-running-AutoHotkey.exe\Lib\ ; Standard library.
; If not in any of those, then add an #Include at the top pointing to the file.

; Create a ListView to display the list of info gathered
Gui Add, ListView, Grid r30 w500 Sort, Process|Tooltip|Handle

; Get all of the icons in the system tray using Sean's TrayIcon library
oIcons := TrayIcon_GetInfo()

; Loop through the info we obtained and add it to the ListView
Loop, % oIcons.MaxIndex()
{
 proc := oIcons[A_Index].Process
 ttip := oIcons[A_Index].tooltip
 hWnd := oIcons[A_Index].hWnd
 
 LV_Add(, proc, ttip, hWnd)
}

LV_ModifyCol()

Gui Show, Center, System Tray Icons
Return

GuiEscape:
GuiClose:
 ExitApp
This works for me on Windows 10. Let me know if it works for you.
I have tested it in Windows 10 and have found the library in the first post only sees visible icons while the library at post https://autohotkey.com/boards/viewtopic ... 9186#p9186 only sees hidden icons.

Using Windows 10 v 1709 build 16299.64 and AHK 1.1.26.01
Vince42
Posts: 6
Joined: 05 Feb 2016, 14:41

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

24 Nov 2017, 16:38

Maybe there will be a "universal" version of TrayIcon, which would a) display visible and hidden icons and b) deliver information about the state of visibility in the future - I will try it again, as soon as I get all my SysTray icons listed.

it would also be cool, if the system icons like network connection, battery, sound, language and clock would be clickable as well.
RiseUp
Posts: 28
Joined: 01 Oct 2013, 21:27

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

24 Nov 2017, 23:33

Aenfa wrote:I have tested it in Windows 10 and have found the library in the first post only sees visible icons while the library at post https://autohotkey.com/boards/viewtopic ... 9186#p9186 only sees hidden icons.

Using Windows 10 v 1709 build 16299.64 and AHK 1.1.26.01
Thank you, Aenfa, for your testing and reporting. :thumbup:
Vince42 wrote:Maybe there will be a "universal" version of TrayIcon, which would a) display visible and hidden icons and b) deliver information about the state of visibility in the future - I will try it again, as soon as I get all my SysTray icons listed.

it would also be cool, if the system icons like network connection, battery, sound, language and clock would be clickable as well.
I've made a change to the library's code and put it up on Github, but I'll post it here, too:
TrayIcon.ahk
(12.36 KiB) Downloaded 620 times
Hopefully, this should work for both the hidden and the visible tray icons. Once you have the newest TrayIcon.ahk in one of your library locations, try this code that should list all of your tray icons, both visible and hidden:

Code: Select all

#NoEnv							; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input					; Recommended for new scripts due to its superior speed and reliability.

; This script assumes that TrayIcon.ahk is in one of your library locations:
;    %A_ScriptDir%\Lib\                                  ; Local library - requires v1.0.90+.
;    %A_MyDocuments%\AutoHotkey\Lib\                     ; User library.
;    path-to-the-currently-running-AutoHotkey.exe\Lib\   ; Standard library.
; If not in any of those, then add an #Include at the top pointing to the file.

; Create a ListView to display the list of info gathered
Gui Add, ListView, Grid r30 w700 Sort, Process|Tooltip|Visible|Handle

; Get all of the icons in the system tray using Sean's TrayIcon library
oIcons := TrayIcon_GetInfo()

; Loop through the info we obtained and add it to the ListView
Loop, % oIcons.MaxIndex()
{
    proc := oIcons[A_Index].Process
    ttip := oIcons[A_Index].tooltip
	tray := oIcons[A_Index].Tray
    hWnd := oIcons[A_Index].hWnd
    
	vis := (tray == "Shell_TrayWnd") ? "Yes" : "No"
	
    LV_Add(, proc, ttip, vis, hWnd)
}

LV_ModifyCol()
LV_ModifyCol(3, "AutoHdr")          ; Auto-size the 3rd column, taking into account the header's text

Gui Show, Center, System Tray Icons
Return

GuiEscape:
GuiClose:
    ExitApp
Last edited by RiseUp on 07 Dec 2017, 21:57, edited 1 time in total.
Vince42
Posts: 6
Joined: 05 Feb 2016, 14:41

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

25 Nov 2017, 17:00

:bravo: OMG! What can I say! It works!!! Thank you so much!
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

12 Feb 2018, 09:24

@FanaticGuru your code tries to free hProc with VirtualFreeEx though the actual variable that should be freed is pRB - I hop you can correct this otherwise this script leaks memory.
Recommends AHK Studio
SquirrelHugger
Posts: 17
Joined: 23 Feb 2018, 04:17

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

13 Mar 2018, 07:02

I am trying to use this to simulate a double click on a specific system tray icon. I am really stupid and new when it comes to this, how should I go about doing what I am trying to do?

I know that I need to use the 'TrayIcon_Button' function, but do I have to include the file in my script? Or should the script be running? Excuse my noobness :D

EDIT: I am not getting any errors while using the following code, but nothing is happening

Code: Select all

#Include %A_ScriptDir%\Miscellaneous\TrayIcon.ahk
TrayIcon_Button("qbittorrent.exe")
:morebeard:
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

13 Mar 2018, 09:22

i created a TrayIcon_test.ahkL
linked ahkL to "F:\portable\AutoHotkey_L1.1.28\AutoHotkeyU64.exe"
an tried this with no result:

Code: Select all

#SingleInstance force
#Include TrayIcon.ahk ; https://autohotkey.com/download/1.1/
#NoEnv							; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input					; Recommended for new scripts due to its superior speed and reliability.
; Create a ListView to display the list of info gathered
Gui Add, ListView, Grid r30 w700 Sort, Process|Tooltip|Visible|Handle
Whats wrong? thanks
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

13 Mar 2018, 17:19

nnnik wrote:@FanaticGuru your code tries to free hProc with VirtualFreeEx though the actual variable that should be freed is pRB - I hop you can correct this otherwise this script leaks memory.
Man, you have a sharp eye.

I believe it should be something like this:

Code: Select all

hProc := DllCall("OpenProcess", UInt, 0x38, Int, 0, UInt, pidTaskbar)
; returns base address actually used; parameters = hProcess (from above), lpAddress, dwSize, flAllocationType, flProtect
pRB   := DllCall("VirtualAllocEx", Ptr, hProc, Ptr, 0, UPtr, 20, UInt, 0x1000, UInt, 0x4)


; parameters = hProcess (from above "OpenProcess"), lpAddress (from above returned by "VirtualAllocEx"), dwSize, dwFreeType
DllCall("VirtualFreeEx", Ptr, hProc, Ptr, pRB, UPtr, 0, Uint, 0x8000)
DllCall("CloseHandle", Ptr, hProc)
Will also modify the script in my post.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

13 Mar 2018, 18:52

RiseUp wrote:Hopefully, this should work for both the hidden and the visible tray icons.
I updated my script at: https://autohotkey.com/boards/viewtopic ... 9186#p9186

My first attempt at fixing this for Windows 10 was something of a hack that only worked mostly by accident. Your solution of just looping again works but is kind of a hack to in that basically in Windows 10 you want ToolbarWindow323 for the Shell_TrayWnd.

I did a hack of checking Windows version and trying to if-then the right ToolbarWindow32?.

Windows seems to just keep making ToolbarWindow32 and putting a number on the end as needed, so even looping to 3 is no guarantee to continue working. The Shell_TrayWnd is not always 3.

I took what is hopefully a better approach and modified the function TrayIcon_GetTrayBar which all along was supposed to be the function to get the correct number before Windows introduced the NotifyIconOverflowWindow.

Maybe someone will find it useful although there is not really a definitive TrayIcon.ahk update from the original work Sean.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
SquirrelHugger
Posts: 17
Joined: 23 Feb 2018, 04:17

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

13 Mar 2018, 22:05

Hey @FanaticGuru

I am having difficulty using your script. I tried your script and the example script and I am getting this:
host.ahk.png
host.ahk.png (12.32 KiB) Viewed 9501 times
No problem there, see the qbittorrent.exe at #13? I am trying to simulate a left mouse button click.
I tried the following:

Code: Select all

TrayIcon_Button( "qbittorrent.exe" )
But it did not work. Would appreciate your input on this. Am I doing something wrong?
:morebeard:
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

14 Mar 2018, 01:18

SquirrelHugger wrote:Hey @FanaticGuru ...

Code: Select all

TrayIcon_Button( "qbittorrent.exe" )
But it did not work. ...
hi and sorry. :) how you did that? to me the follwiing has no effect:

Code: Select all

#SingleInstance force
#NoEnv							; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input					; Recommended for new scripts due to its superior speed and reliability.

#Include TrayIcon.ahk ; https://autohotkey.com/download/1.1/

TrayIcon_Button( "skype.exe" )  ; <== no effect? normal? 14.03.2018 07:16

; Create a ListView to display the list of info gathered
; Gui Add, ListView, Grid r30 w700 Sort, Process|Tooltip|Visible|Handle ; <== no effect?
SquirrelHugger
Posts: 17
Joined: 23 Feb 2018, 04:17

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

14 Mar 2018, 05:41

SL5 wrote:
SquirrelHugger wrote:Hey @FanaticGuru ...

Code: Select all

TrayIcon_Button( "qbittorrent.exe" )
But it did not work. ...
hi and sorry. :) how you did that? to me the follwiing has no effect:

Code: Select all

#SingleInstance force
#NoEnv							; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input					; Recommended for new scripts due to its superior speed and reliability.

#Include TrayIcon.ahk ; https://autohotkey.com/download/1.1/

TrayIcon_Button( "skype.exe" )  ; <== no effect? normal? 14.03.2018 07:16

; Create a ListView to display the list of info gathered
; Gui Add, ListView, Grid r30 w700 Sort, Process|Tooltip|Visible|Handle ; <== no effect?
That's the thing, it didn't work for me. That's why I am asking for help.
From the documentation, it appears that it should work the way I wrote it.

EDIT: well it worked when I tried to double click another tray icon, but not for qbittorrent.exe
Any idea why?
:morebeard:
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

14 Mar 2018, 13:31

SquirrelHugger wrote:EDIT: well it worked when I tried to double click another tray icon, but not for qbittorrent.exe
Any idea why?
The reason some tray icons work and others do not probably has to do with permissions. Some tray icons are probably running as a higher-privileged process that basically don't want to be messed with by a lower-privileged process. The function uses a PostMessage to tell the program its tray icon has been clicked but PostMessage could be used to control the program in lots of other ways which the program does not want without the right permissions.

It is probably more complicated than just running your script as an administrator. There are probably ways to get around it but I am no expert on User Account Control and User Interface Privilege Isolation. The function is actually pretty simple and small but the code to get around the permissions is probably going to be much more complicated and long.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
SquirrelHugger
Posts: 17
Joined: 23 Feb 2018, 04:17

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

15 Mar 2018, 10:13

@FanaticGuru thank you for your input. I'll eventually find a way through this somehow :D
:morebeard:
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

28 Mar 2018, 07:49

Looks like this lib is still getting some love :D

I will reference the most updated versions in the OP, because I stopped looking at it while ago!
ABCza on the old forum.
My GitHub.
RiseUp
Posts: 28
Joined: 01 Oct 2013, 21:27

Re: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit

13 Feb 2019, 15:32

FanaticGuru wrote:
13 Mar 2018, 18:52
RiseUp wrote:Hopefully, this should work for both the hidden and the visible tray icons.
I updated my script at: https://autohotkey.com/boards/viewtopic.php?p=9186#p9186

My first attempt at fixing this for Windows 10 was something of a hack that only worked mostly by accident. Your solution of just looping again works but is kind of a hack to in that basically in Windows 10 you want ToolbarWindow323 for the Shell_TrayWnd.

I did a hack of checking Windows version and trying to if-then the right ToolbarWindow32?.

Windows seems to just keep making ToolbarWindow32 and putting a number on the end as needed, so even looping to 3 is no guarantee to continue working. The Shell_TrayWnd is not always 3.

I took what is hopefully a better approach and modified the function TrayIcon_GetTrayBar which all along was supposed to be the function to get the correct number before Windows introduced the NotifyIconOverflowWindow.

Maybe someone will find it useful although there is not really a definitive TrayIcon.ahk update from the original work Sean.

FG
Thank you for your additional fixes, as well as your explanation of the theory behind them. :thumbup:

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 110 guests