Jump to content

Trouble removing tray icons


OiMunk
 Share

Recommended Posts

I'm having some difficulty getting this script to run properly, it seems to occasionally remove the wrong tray icon. I'm not sure if the TrayIconTitle numbers don't correspond to the _SysTrayIconRemove numbers..

#include "SysTray_UDF.au3"

Opt("WinTitleMatchMode", 2)

$tray=_SysTrayIconTitles()

$count=UBound($tray)-1

for $i = 0 to $count

If StringInStr($tray[$i],"onnections") or StringinStr($tray[$i],"troke") or StringinStr($tray[$i],"LCDM")Then ;targets specific icons

_SysTrayIconRemove($i) ;removes the icon

Sleep(1111)

EndIf

Next

;any ideas? thanks,

Link to comment
Share on other sites

Hi! Try this:

#include <GuiToolBar.au3>

_SysTray_HideItem("Winamp", 1)

;========================================================================================
;
;$iTitle - The title of the item in Windows system tray
;+(you can see the title of the item when mouse cursor hovered on item, enough substring)
;
;$iState - [optional] The icon state, 1 = hide, 0 = visible, default is 1.
;
;========================================================================================

Func _SysTray_HideItem($iTitle, $iState = 1)
    If Not $iTitle Then
        MsgBox(16, "Error", "Please indicate title")
        Return
    EndIf
    
    Local $hToolbar, $ItemCount, $ID, $i
    
    If $iState = 1 Then
        $iState = $TBSTATE_HIDDEN
    Else
        $iState = $TBSTATE_ENABLED
    EndIf
    
    $hToolbar = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then Return
    
    $ItemCount = _GUICtrlToolbar_ButtonCount($hToolbar)
    If $ItemCount = 0 Then Return
    
    For $i = 0 To $ItemCount
        $ID = _GUICtrlToolbar_IndexToCommand($hToolbar, $i)
        If StringInStr(_GUICtrlToolbar_GetButtonText($hToolbar, $ID), "Winamp") Then
            _GUICtrlToolbar_SetButtonState($hToolbar, $ID, $iState)
            Return
        EndIf
    Next
    MsgBox(48, "Message", "Required item not found")
EndFunc

:)

Edited by rasim
Link to comment
Share on other sites

Thanks!

I had to replace

If StringInStr(_GUICtrlToolbar_GetButtonText($hToolbar, $ID), "WinAmp") Then

;with

If StringInStr(_GUICtrlToolbar_GetButtonText($hToolbar, $ID), $iTitle) Then

;but it works perfectly now. cheers,

Edited by OiMunk
Link to comment
Share on other sites

Hi! Try this:

Very useful script!! I have a Cmd Window with DosKey customizations.. sort of like a clunky Slickrun imitation, that I load on Windows startup. I've been looking everywhere for a means to remove the Taskbar Button without hiding the window or removing it from Alt-Tab list. A few edits to this script and bingo!!! :)

Link to comment
Share on other sites

I've run into a bit of a snag in Vista. What I'm trying to do is: launch the customized command prompt at startup; change its title so that Taskbar grouping won't add onto it if I open another command prompt; then hide the Taskbar button. This snippet works in XP.

ShellExecute("C:\Documents and Settings\Owner\Desktop\Command Prompt.lnk")
Sleep(1000)
If Not WinSetTitle("Command Prompt","","DosKey") Then
    MsgBox(0,"DosNoTaskButton","Command Prompt Window Not Found",3)
    Exit
EndIf
WinActivate("DosKey")
_SysTray_HideItem("DosKey", 1)

I made the changes for Vista(C:\Users instead of Documents and Settings etc.) and the command prompt launches. I use Title "Administrator: Command Prompt" and WinSetTitle does not complain. But the title in the Command Window is not changed.

A bit baffling. :)

Link to comment
Share on other sites

I got it. Just had to use the handle functions instead. WinGetHandle then _WinAPI_SetWindowText.

Ahh jeez!! There's always another wrinkle when it comes to Windows Shell. :) Turns out as soon as I run a command, the window title will reset. I was trying to do it the hard way. Looks like the easiest method is to create a shortcut in the Programs Startup Folder from the custom command prompt, and rename it. Then just use the _SysTray_HideItem() to hide the button.

Edited by MilesAhead
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...