Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Extract Informations about TrayIcons


  • Please log in to reply
149 replies to this topic
Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
It will display the infos of the current tray icons:
exename, classname, hWnd, nMsg (:Message ID), uID (:Icon ID), idn (:Button ID)

1) Using idn, can Hide/Show the tray icons:
HideTrayIcon(idn, True/False)

Can still control the trayicon after hidden, e.g., right-click:
PostMessage, nMsg, uID, 0x204, , ahk_id %hWnd%
PostMessage, nMsg, uID, 0x205, , ahk_id %hWnd%

2) Using 1-based index, can rearrage the trayicon from idxOld to idxNew:
MoveTrayIcon(idxOld, idxNew)

Actually, it can appy equally to task buttons too, replacing the last 1 in ToolbarWindow321 with appropriate number.

DOWNLOAD TrayIcon.ahk.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Kewl. I was looking at MSDN and I noted that adding tray icos can be done too.
Posted Image

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Kewl. I was looking at MSDN and I noted that adding tray icos can be done too.

Yes, basically using the same Shell_NotifyIcon, but need to provide more informations. The most important one may be hIcon. As a matter of fact, TrayIcons() function can extract hIcon too, so, can add back the deleted tray icons, in principle. However, there is one glitch: hIcon is not always the correct one for some apps, e.g., Process Explorer etc. So, I decided to not implement it.

May consider using HideTrayIcon(idn, true/false) (:note idn, it's not idx) instead. However, the traybar won't resize even after hiding a trayicon.
(:This symptom is now cured, so, it would be a better solution now.)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
So, are you going to do Adding tray icons or me ?

I imagine this interface for the start:

AddTrayIcon( iconPath, onMouseLeft, onMouseRight="", onMouseMove="" )

with iconPath that can be specified as string or number in which case icon handle should be seen.
Posted Image

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

So, are you going to do Adding tray icons or me ?

What purpose do you have in mind to add tray icons?
I may add an option to restore the tray icons removed although it won't work always. But, I don't have any further plan. So, I suppose it's up to you.

AddTrayIcon( iconPath, onMouseLeft, onMouseRight="", onMouseMove="" )
Basically, need hWnd, MessageID, and IconID which controls the tray icon and communicate with the shell. I think this can be done using OnMessage().
And, yes, then hIcon and sTooltip.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

What purpose do you have in mind to add tray icons?

You mean, besides setting multiple tray icons per script and things like that ? Like, CPU usage and MEM usage ? Script creating custom menus, and eatch menu being able to represent itself via tray ? I mean... why the fuk do you need tray icons in windows at all....

So, I suppose it's up to you.

i suppose...
Posted Image

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
As a matter of fact, I seldom use tray icons. The purpose of this script was to not click tray icons, at least for me.

XavierGr
  • Members
  • 48 posts
  • Last active: Feb 02 2012 04:59 PM
  • Joined: 15 Jul 2006
Excellent Script Sean! I was looking something like this for months.
This can be utilized for a complete boss mode script in order to hide all running processes instead of terminating them.

Thanks again for these wonderful functions. :)
One hotkey to rule them all!

Aurelain
  • Members
  • 1 posts
  • Last active: Mar 14 2007 09:38 PM
  • Joined: 10 Mar 2007
Sean's RemoveTrayIcon function (see above) already does AddTrayIcon, as long as it's passed the proper parameters.

For example, if one were to add this to Sean's script:
Process, Exist
WinGet, hWnd,, ahk_pid %ErrorLevel%
RemoveTrayIcon(hWnd,999,0,0,0)
you would already have a new blank icon. I changed the hWnd to the current one, the uID to a random one, a blank nMsg, a blank hIcon and the command to ADD (which is 0, while MODIFY is 1 and REMOVE is 2).

An interesting script would be the following:
#Persistent
DetectHiddenWindows, On
Process, Exist
WinGet, hWnd,, ahk_pid %ErrorLevel%
AddTrayIcon(hWnd,101,0,0,0)
AddTrayIcon(hWnd,102,0,0,0)
AddTrayIcon(hWnd,103,0,0,0)


AddTrayIcon(hWnd, uID, nMsg = 0, hIcon = 0, nRemove = 2)
{
   VarSetCapacity(ni, 68, 0)
   EncodeInteger(&ni + 0, VarSetCapacity(ni))
   EncodeInteger(&ni + 4, hWnd)
   EncodeInteger(&ni + 8, uID)
   EncodeInteger(&ni +12, 1|2|4)
   EncodeInteger(&ni +16, nMsg)
   EncodeInteger(&ni +20, hIcon)
   DllCall("shell32\Shell_NotifyIconA", "Uint", nRemove, "Uint", &ni)
}


EncodeInteger(ref, val, nSize = 1)
{
   DllCall("ntdll\RtlFillMemoryUlong", "Uint", ref, "Uint", nSize * 4, "Uint", val)
}
Why would anyone want that? Well, there are some people who place controls on the taskbar and need some "spacers"...

raven-gm
  • Guests
  • Last active:
  • Joined: --
is there a way to use this to get the tooltip of a perticular icon?

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

is there a way to use this to get the tooltip of a perticular icon?

Sure. Use exename like
TrayIcons("autohotkey.exe")
If there exist multiple instances, it will also produce multiple results.

Now, I suppose it's easy to edit it to fit the need.

raven-gm
  • Guests
  • Last active:
  • Joined: --
Oh, ok.

I did it a different way, retrieving all the info then searching it for the strings I needed, but it looks like your way is a lot faster.

Thanks!

BoBo
  • Guests
  • Last active:
  • Joined: --
Impressing. Thx for sharing it. 8)

keyboardfreak
  • Members
  • 217 posts
  • Last active: Sep 27 2010 07:21 PM
  • Joined: 09 Oct 2004
Thanks for this script. It's just what I needed. There was an application which appeared from time to time in the tray, but it disappeared in 1 sec, so I couldn't click on it to determine what it is.

I added this code to the beginning of the script to pop up a message box when a new icon appears in the tray:
prevtray =
loop
{
  tr := TrayIcons()
  if (tr <> prevtray)
    MsgBox % tr
  prevtray := tr
  sleep 1000
}
and put this code before the line "sTrayIcons .= ..." to filter out my usual programs:
if (instr(sTooltip, "volume") or ...)
                   continue
The misterious program turned to be the autoupdater of my firewall.

Thanks again for this script.

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004

What purpose do you have in mind to add tray icons?

there was a time when when i wanted to write my own small, custom shell to replace explorer. the roadblock i faced was that i didn't know how to add tray icons of applications (well, dllcall wasn't there in ahk at that time either).
now that could be one use.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat