Jump to content
Sign in to follow this  
Lope

[Solved enough] Hide Tray Icon (with empty title) of program I ShellExecute

Recommended Posts

Lope

Currently Trying to get the bitmap index of another program's tray icon using. See

===================================================================

Try comment and uncomment the 3rd line... I can't get the Param in x86.

What I'm trying to do is hide the tray icon of a program I run in my script.

The difficulty is that the program creates a tray icon with a blank title. (there can be various tray icons with no title, so I can't hide ALL icons with blank titles)

So my solution was to make an array of the Params (belonging to visible icons with empty titles) before I shellexecute the program, then see what new icon appears who's param is not in the array, then hide that Icon.

If anyone has a cleverer solution, (like determining a Tray Icon's owning process) let me know :graduated:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=Silverblade.ico
;#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
 
#Include <GuiToolBar.au3>
HotKeySet("{ESC}", "_Quit")
Opt("WinTitleMatchMode", 4)
Global $hTray = WinGetHandle("[CLASS:Shell_TrayWnd]")
Global $hToolbar = ControlGetHandle($hTray, "", "[CLASSNN:ToolbarWindow321]")
Global $iCnt = _GUICtrlToolbar_ButtonCount($hToolbar)
ConsoleWrite("Debug: $iCnt = " & $iCnt & @LF)
Global $iCmdVolume = -1
Global $sMsg, $sText, $iCmd
For $n = 0 To $iCnt - 1
    $sMsg = "Index: " & $n
    $iCmd = _GUICtrlToolbar_IndexToCommand($hToolbar, $n)
    $sMsg &= "  CommandID: " & $iCmd
    $sText = _GUICtrlToolbar_GetButtonText($hToolbar, $iCmd)
    If StringInStr($sText, "Volume") Then
  $iCmdVolume = $iCmd
  Msgbox(0,"",_GUICtrlToolbar_GetButtonParam($hToolbar,$iCmd));Returns 0 in x86 but gives a param on x64?
EndIf
    $sMsg &= "  Text: " & $sText
    ConsoleWrite("Debug: " & $sMsg & @LF)
Next
ConsoleWrite("Debug: $iCmdVolume = " & $iCmdVolume & @LF)
Global $bolVisible = True
While 1
    $bolVisible = Not $bolVisible
    If $bolVisible Then
        _GUICtrlToolbar_SetButtonState($hToolbar, $iCmdVolume, $TBSTATE_ENABLED)
    Else
        _GUICtrlToolbar_SetButtonState($hToolbar, $iCmdVolume, $TBSTATE_HIDDEN)
    EndIf
    Sleep(1000)
WEnd
Func _Quit()
    _GUICtrlToolbar_SetButtonState($hToolbar, $iCmdVolume, $TBSTATE_ENABLED)
    Exit
EndFunc
Edited by Lope

Share this post


Link to post
Share on other sites
sleepydvdr

Add this to the top of your script:

#NoTrayIcon

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
Lope

You misunderstood my question. I want to remove the tray icon from another application that I shellexecute.

Another solution would be if I could find the handle of Icons in the systray.

Share this post


Link to post
Share on other sites
Lope

I found a solution.

I just set all tray icons with blank titles to ' ' before shellexecuting the EXE. Then after Shellexecuting the EXE I look for a tray icon with a blank title and hide it.

The only thing that snagged me is when I change Tray Icon titles with _GUICtrlToolbar_SetButtonText() (even using 'test' etc) The new tooltip was not displaying. That threw me off, until I realized even though it doesn't update in the system tray, it still works for my purposes :graduated: Maybe a tray refresh of some kind would sort that out.

Heres my working code:

#Include <GuiToolBar.au3>
Global $params[100]
Global $paramcount=0
Global $p
Func FindBlankTrayIcons($musthide=False)
Local $hSysTray = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
;Msgbox (0,"toolbar",$hToolbar )
For $n = 0 To _GUICtrlToolbar_ButtonCount($hSysTray) - 1
  Local $iCmd = _GUICtrlToolbar_IndexToCommand($hSysTray, $n)
  Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray, $iCmd)
  Local $visible= _GUICtrlToolbar_GetButtonState($hSysTray, $iCmd)==$TBSTATE_ENABLED
  If ($sText=='') And $visible Then
   If Not $musthide Then
    _GUICtrlToolbar_SetButtonText($hSysTray, $iCmd,' ')
   Else
    _GUICtrlToolbar_SetButtonState($hSysTray, $iCmd, $TBSTATE_HIDDEN)
   EndIf
  EndIf
Next
EndFunc
Edited by Lope

Share this post


Link to post
Share on other sites
Lope

Okay, that last bit of code didn't work reliably either.

The reason I wanted to get Icon Handles is I thought the Command numbers might be different every time you use _GUICtrlToolbar_IndexToCommand.

But it seems calling that function a few times within a brief space of time, it gives the same numbers. (good)

So here is the new, reliable code :graduated:

#Include <GuiToolBar.au3>
#Include <Array.au3>
Local $hSysTray = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
 
Local $TrayIconList[200]
Global $TrayIconListCount
 
Func FindTrayIcons($store=False)
If $store Then $TrayIconListCount=0
Local $count
For $n = 0 To _GUICtrlToolbar_ButtonCount($hSysTray) - 1
Local $iCmd = _GUICtrlToolbar_IndexToCommand($hSysTray, $n)
Local $visible= _GUICtrlToolbar_GetButtonState($hSysTray, $iCmd)==$TBSTATE_ENABLED
If $visible Then
$count += 1
If $store Then
$TrayIconList[$TrayIconListCount]=$iCmd
$TrayIconListCount +=1
EndIf
EndIf
Next
Return $count
EndFunc
 
Func HideNewTrayIcons()
For $n = 0 To _GUICtrlToolbar_ButtonCount($hSysTray) - 1
Local $iCmd = _GUICtrlToolbar_IndexToCommand($hSysTray, $n)
Local $visible= _GUICtrlToolbar_GetButtonState($hSysTray, $iCmd)==$TBSTATE_ENABLED
If $visible Then
If _ArrayFindAll($TrayIconList,$iCmd) ==-1 Then _GUICtrlToolbar_SetButtonState($hSysTray, $iCmd, $TBSTATE_HIDDEN)
EndIf
Next
$TrayIconListCount=0
$TrayIconList=0;free memory
EndFunc

and the code that calls it

FindTrayIcons(True)
ShellExecute($path)
For $i = 1 to 4000;wait for tray icon to appear
Sleep(1)
If FindTrayIcons()>$TrayIconListCount Then
HideNewTrayIcons()
ExitLoop
EndIf
Next

works like a beast!

Edited by Lope

Share this post


Link to post
Share on other sites
Lope

I'm having another issue...

The program I'm running changes its tray icon between two different icons while its running.

I'd like to find out which tray icon it has at a given time.

I've tried using this:

_GUICtrlToolbar_GetButtonBitmap in the same way as the other functions above, but it returns 46 for both icons. Sometimes when I run the app it returns 47 for both icons. I ran the app again now and it returned 45 for both icons.

Useless...

Does anyone have any ideas?

How can you get an image handle from the Toolbar Control number?

=================================================

Edit, Okay I've worked around this problem by That tells me when its busy or not, with enough accuracy.

Edited by Lope

Share this post


Link to post
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
Sign in to follow this  

×