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
ManDude
  • Guests
  • Last active:
  • Joined: --

Replace inside the TrayIcons() all occurence of:

Shell_TrayWnd -> NotifyIconOverflowWindow
ToolbarWindow32%idxTB% -> ToolbarWindow321 ; idxTB := GetTrayBar() no longer needed.


If I make those changes I can get info from HIDDEN icons. If I don't make the changes, I can get info from VISABLE icons. How can I combine the two?

  • Guests
  • Last active:
  • Joined: --
I spent a good hour and can only remove tray icons by a cumbersome method. Can someone please explain the best way to hide tray icons for 4 different applications, each with a different exe, in Windows XP? I saw some RegEx code that Sean provided earlier but I don't understand how to use it.

The only method I am using is to (1) use MsgBox to find idn; (2) comment out MsgBox section at top; then (3) enter "HideTrayIcon(16, true)"; (4) repeat process for next tray icon. I'm sure there's a simpler way to do this.

RaptorX
  • Members
  • 751 posts
  • Last active: Feb 19 2015 02:47 AM
  • Joined: 19 Feb 2010
i wrote a little script based on sean's work a while ago that does what you are asking for (or so i think)
give this little piece of code a try and tell me how it works for you.

what it does is that it makes a list of the applications that have tray icons. then you can hide/show the tray icons by ticking/unticking a checkbox.

with that you should be able to hide 4 specific icons and leave the other intact.

DetectHiddenWindows, On
tIcons := TrayIcons(), fr:=True
Gui, add, listview, w400 h500 AltSubmit Grid Checked glvHandler, % "Pid|Tooltip|Process"

Loop, Parse, tIcons,|
{

        
    if a_loopfield contains pid:
        pid:=RegexReplace(RegexReplace(a_loopfield, "Pid:\s"), "\s")
    
    if a_loopfield contains process:
        proc:=RegexReplace(RegexReplace(a_loopfield, "Process:\s"), "\s")
        
    if a_loopfield contains tooltip:
    {
        tooltip:=RegexReplace(a_loopfield, "Tooltip:\s")
        if pid in %proclist%
            continue
        LV_Add("check", pid, tooltip, proc), LV_ModifyCol(), LV_ModifyCol(3, "AutoHdr") proclist.=pid ","
    }
}
Gui, Show
Return

lvHandler:
    Critical 
    LV_GetText(pid, A_EventInfo)
    if (a_guievent = "I" && !fr)
    {
        stat:=inStr(ErrorLevel, "c", True)
        HideTrayIcon(RegexReplace(TrayIcons(pid), ".*idn:\s(\d+).*", "$1"),stat)
    }
    fr:=False
return

TrayIcons(sExeName = "")
{
	WinGet,	pidTaskbar, PID, ahk_class Shell_TrayWnd
	hProc:=	DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
	pProc:=	DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
	idxTB:=	GetTrayBar()
		SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
	Loop,	%ErrorLevel%
	{
		SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
		VarSetCapacity(btn,32,0), VarSetCapacity(nfo,32,0)
		DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
			iBitmap	:= NumGet(btn, 0)
			idn	:= NumGet(btn, 4)
			Statyle := NumGet(btn, 8)
		If	dwData	:= NumGet(btn,12)
			iString	:= NumGet(btn,16)
		Else	dwData	:= NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
		DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 32, "Uint", 0)
		If	NumGet(btn,12)
			hWnd	:= NumGet(nfo, 0)
		,	uID	:= NumGet(nfo, 4)
		,	nMsg	:= NumGet(nfo, 8)
		,	hIcon	:= NumGet(nfo,20)
		Else	hWnd	:= NumGet(nfo, 0,"int64"), uID:=NumGet(nfo, 8), nMsg:=NumGet(nfo,12)
		WinGet, pid, PID,              ahk_id %hWnd%
		WinGet, sProcess, ProcessName, ahk_id %hWnd%
		WinGetClass, sClass,           ahk_id %hWnd%
		If !sExeName || (sExeName = sProcess) || (sExeName = pid)
			VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
		,	DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
		,	DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
		,	sTrayIcons .= "idx: " . A_Index-1 . " | idn: " . idn . " | Pid: " . pid . " | uID: " . uID . " | MessageID: " . nMsg . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . " | Tooltip: " . sTooltip . "|`n"
	}
	DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
	DllCall("CloseHandle", "Uint", hProc)
	Return	sTrayIcons
}

HideTrayIcon(idn, bHide = True)
{
	idxTB := GetTrayBar()
	SendMessage, 0x404, idn, bHide, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_HIDEBUTTON
	SendMessage, 0x1A, 0, 0, , ahk_class Shell_TrayWnd
}

GetTrayBar()
{
	ControlGet, hParent, hWnd,, TrayNotifyWnd1  , ahk_class Shell_TrayWnd
	ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
	Loop
	{
		ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
		If  Not	hWnd
			Break
		Else If	hWnd = %hChild%
		{
			idxTB := A_Index
			Break
		}
	}
	Return	idxTB
}

--EDIT
havent fixed it for unicode. if run with unicode version of AHK the tooltip text might look like chinese characters :p
AutoHotkey Toolkit [Main Project]
Scintilla Wrapper
LexAHKL

  • Guests
  • Last active:
  • Joined: --
Thanks for sharing that script. It seems to do what I want - and it's very easy to use - but it seems to have some odd behavior. After you hide some tray icons, if you run an application that places a new icon in the tray, one of the hidden icons reappears. Also, the script has duplicated a Windows network connection status icon in my tray - I can't interact with the new icon to dismiss it for some reason. Also, the list that appears doesn't show all the icons in the tray.

I was hoping for help putting together something simpler, which hides (or restores) tray icons associated with exes listed in the script. Sean provided some regex code for this above, but I could only get it to work if I included it the code in the script once, so it would only remove one icon. I guess I could create 5 scripts, one for each icon, but that's a bit cumbersome to manage.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Does anyone have a copy of this?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
These look alright to me:
http://webcache.goog... ... ayIcon.ahk
http://webcache.goog... ... Button.ahk

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Thanks ;)

will89
  • Guests
  • Last active:
  • Joined: --
Dead again, anyone have a mirror?

Thanks!

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

These look alright to me:
http://webcache.goog...ercontent.com/s ... ayIcon.ahk
http://webcache.goog...ercontent.com/s ... Button.ahk

http://dl.dropbox.co...'s_TrayIcon.zip

KLEBESTIFT
  • Members
  • 1 posts
  • Last active: Feb 05 2013 10:01 PM
  • Joined: 05 Feb 2013

<!-- m -->http://dl.dropbox.co...6428211/AHK/Oth ... ayIcon.zip<!-- m -->

 
Dead again. Anyone have another copy? Maybe we could post it in code tags so the links can't die again.

 

Edit: Am i correct in assuming the TrayIcons function in RaptorX's post above is the same as in the OP?



SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
I fixed my link: http://dl.dropbox.co...'s_TrayIcon.zip

tedych
  • Members
  • 7 posts
  • Last active: Oct 26 2015 12:50 PM
  • Joined: 10 Jul 2011

I needed a way to enumerate and doubleclick a particular icon in the tray. I tried many possible "solutions" here and there, and none of them worked almost at all, on Win7 x64.

I had many troubles making many of more advanced functionalities to work to some extent, and the complexity of autohotkey scripts that implement such functionalities can become a nightmare. After some point it is better to use a full fledged programming environment, where I would have more luck implementing what I want.

I'm using AHK for many simple things primarily because of that - like key reassignments etc.

I'm yet to find a reliable way to enumerate tray icons and be able to do simple things like click or double click a particular icon. But I've given up after spending several hours trying.

The TrayIcon*() implementations I found here, are either not working at all, or not finding any icons, or finding the icons but with empty data fields. I ccan't connect them to their corresponding windows and window titles (I have few icons with the same look and tooltips frmo the same exe's but different instances and window titles accordingly.

With AHK you should be a master programmer to do some things that go beyond the simple and obvious things, unfortunately.



Kungi
  • Members
  • 1 posts
  • Last active: Oct 02 2013 07:29 PM
  • Joined: 02 Oct 2013

Alright I need some help. Since I am not good with script code and whatnot. After googling this page and notunusual gave me all the script code I needed. I'm mainly using this for the play-log to show up on my stream. It's working fine atm but I don't need to to keep a history of previous songs played with the date/time. I'm looking around the code and I thought just deleting the previous song code would work but didn't. Which part of the code do I have to alter so it only keeps the current song and refreshes every time the changes and not keep a history on it? Please and Thank you for any information. 



RiseUp
  • Members
  • 38 posts
  • Last active: Jan 04 2016 01:42 PM
  • Joined: 06 Dec 2007

Which part of the code do I have to alter so it only keeps the current song and refreshes every time the changes and not keep a history on it? Please and Thank you for any information.


Have you tried the updated code that I posted on the topic regarding notunusual's script?

Here is the link to my post there.
 
Reply on that topic to let me know how it goes.

yogalD11
  • Members
  • 1 posts
  • Last active: Jan 15 2014 03:34 AM
  • Joined: 14 Jan 2014

Edit: nevermind