Tray Icon verstecken

  • Hi ich probiere schon den ganzen tag herum aber ich schaffe es einfach nicht...

    Ich hab mir hier: http://www.autoitscript.com/forum/index.php?showtopic=13704&st=0

    Die folgende Funktionen herausgesucht:

    Spoiler anzeigen
    [autoit]

    ; ----------------------------------------------------------------------------
    ;
    ; AutoIt Version: 3.1.1 Beta
    ; Author: Tuape
    ;
    ; Script Function:
    ; Systray UDF - Functions for reading icon info from system tray / removing
    ; any icon.
    ;
    ; Last Update: 7/14/05
    ; Requirements: AutoIt3 Beta - tested on WindowsXP, might also work in win2000
    ;
    ; Functions:
    ; _SysTrayIconCount() - Get count of all systray icons
    ; _SysTrayIconTitles() - Get titles of all programs that have icon on systray
    ; _SysTrayIconProcesses() - Get list of all process names that have icon in systray (hidden or visible)
    ; _SysTrayIconPids() - Get list of all parent process id's that own an icon in systray (hidden or visible)
    ; _SysTrayIconRemove($index) - Remove icon (removes completely, not just hide)
    ; ($wintitle or $process) - Get icon index based on process name or wintitle
    ; _SysTrayIconTooltip($index) - Get tooltip text of an icon based on index
    ;
    ; Notes:
    ; Some systray icons are actually hidden, so _SysTrayIconCount will probably return more than you see on systray.
    ; Some icons don't have window title on them. However, _SysTrayIconPids() & _SysTrayIconProcesses
    ; do return correct (parent) pid or process name
    ; ----------------------------------------------------------------------------
    #NoTrayIcon

    [/autoit] [autoit][/autoit] [autoit]

    Const $TB_DELETEBUTTON = 1046
    Const $TB_GETBUTTON = 1047
    Const $TB_BUTTONCOUNT = 1048
    Const $TB_GETBUTTONTEXT = 1099
    Const $TB_GETBUTTONINFO = 1089
    Const $TB_HIDEBUTTON = 1028 ; WM_USER +4
    Const $TB_GETITEMRECT = 1053
    Const $TB_MOVEBUTTON = 1106 ; WM_USER +82
    Const $WM_GETTEXT = 13 ; Included in GUIConstants
    Const $PROCESS_ALL_ACCESS = 2035711
    Const $NO_TITLE = "---No title---" ; text that is used when icon window has no title

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Function Name: _SysTrayIconVisible($flag, $index)
    ; Description: Hides / unhides any icon on systray
    ;
    ; Parameter(s): $flag = hide (1) or show (0) icon
    ; $index = icon index. Can be queried with _SysTrayIconIndex()
    ;
    ; Requirement(s): AutoIt3 Beta
    ; Return Value(s): On Success - Returns 1 if operation was successfull / 0 if
    ; icon was already hidden/unhidden
    ; On Failure - If invalid parameters, returns -1 and sets error
    ; to 1
    ;
    ; Author(s): Tuape
    ;
    ;===============================================================================
    Func _SysTrayIconVisible($flag, $index)
    If $flag < 0 or $flag > 1 or Not IsInt($flag) Then
    SetError(1)
    return -1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $hWnd = _FindTrayToolbarWindow()
    Local $return

    [/autoit] [autoit][/autoit] [autoit]

    Local $str = "int;int;byte;byte;byte[2];dword;int";char[128]"
    Dim $TBBUTTON = DllStructCreate($str)
    Dim $TBBUTTON2 = DllStructCreate($str)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Local $pId
    Local $text
    Local $procHandle
    Local $bytesRead
    Local $info
    Local $lpData

    [/autoit] [autoit][/autoit] [autoit]

    Local $ret = DLLCall("user32.dll","int","GetWindowThreadProcessId", "hwnd", $hWnd, "int*", -1)
    If Not @error Then
    $pId = $ret[2]
    Else
    ConsoleWrite("Error: Could not find toolbar process id, " & @error & @LF)
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    Return -1
    EndIf
    $procHandle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $PROCESS_ALL_ACCESS, 'int', False, 'int', $pId)
    If @error Then
    ConsoleWrite("Error: Could not read toolbar process memory, " & @error & @LF)
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    return -1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $lpData = DLLCall("kernel32.dll","int","VirtualAllocEx", "int", $procHandle[0], "int", 0, "int", DllStructGetSize ( $TBBUTTON ), "int", 0x1000, "int", 0x04)
    If @error Then
    ConsoleWrite("VirtualAllocEx Error" & @LF)
    $TBBUTTON = 0
    $TBBUTTON2 = 0
    Return -1
    Else
    DLLCall("user32.dll","int","SendMessage", "hwnd", $hWnd, "int", $TB_GETBUTTON, "int", $index, "ptr",$lpData[0]);e(hwnd, TB_GETBUTTON, index, (LPARAM)lpData);
    DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $procHandle[0], 'int', $lpData[0], 'ptr', DllStructGetPtr($TBBUTTON2), 'int', DllStructGetSize( $TBBUTTON), 'int', $bytesRead)

    [/autoit] [autoit][/autoit] [autoit]

    $return = DLLCall("user32.dll","int","SendMessage", "hwnd", $hWnd, "int", $TB_HIDEBUTTON, "int", DllStructGetData($TBBUTTON2,2), "long", $flag)
    ;ConsoleWrite(@CRLF & "Return: " & $return[0])

    [/autoit] [autoit][/autoit] [autoit]

    DLLCall("kernel32.dll","int","VirtualFreeEx", "int", $procHandle[0], "ptr", $lpData[0], "int", 0, "int", 0x8000) ;DllStructGetSize ( $TBBUTTON ), "int", 0x8000)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $procHandle[0])

    [/autoit] [autoit][/autoit] [autoit]

    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $TBBUTTON = 0
    $TBBUTTON2 = 0

    [/autoit] [autoit][/autoit] [autoit]

    return $return[0]
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Function Name: _SysTrayIconIndex($name, $mode=0)
    ; Description: Get list of all processes id's that have systray icon
    ; Parameter(s): $name = process name / window title text
    ; $mode 0 = get index by process name (default)
    ; 1 = get index by window title
    ; 2 = get index by icon's tooltip text
    ; Requirement(s): AutoIt3 Beta
    ; Return Value(s): On Success - Returns index of found icon
    ; On Failure - Returns -1 if icon for given process/wintitle
    ; was not found.
    ; - Sets error to 1 and returns -1 in case of bad
    ; arguments
    ; Author(s): Tuape
    ;
    ;===============================================================================
    Func _SysTrayIconIndex($name, $mode=0)
    Local $index = -1
    Local $process
    Local $i
    If $mode < 0 or $mode > 2 or Not IsInt($mode) Then
    SetError(1)
    return -1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $mode = 0 Then
    $process = _SysTrayIconProcesses()

    [/autoit] [autoit][/autoit] [autoit]

    Else
    $process = _SysTrayIconTitles()
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 to Ubound($process)-1
    If $process[$i] = $name Then
    $index = $i
    EndIf
    Next

    [/autoit] [autoit][/autoit] [autoit]

    return $index

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit]


    Die sollten ja reichen oder?

    Nur komme ich jetzt nicht dahinter wie das programm ausgewählt wird von dem das icon versteckt werden soll.

    Meine Systray_test.au3:

    [autoit]

    #include "SysTray_UDF.au3"

    [/autoit][autoit][/autoit][autoit]

    ; -- Example 3 --
    $st_process = "Opera.exe"; change this if needed
    _SysTrayIconVisible(1, _SysTrayIconIndex($st_process))
    ; Note that the icon is hidden
    Sleep(1000)
    _SysTrayIconVisible(0, _SysTrayIconIndex($st_process))

    [/autoit]

    Fehlt mir da noch was oder muss ich da nur noch die variablen richtig anpassen?

  • Du kannst dir nicht einfach ein, zwei Funktionen aus der UDF picken und hoffen, das es dann funktioniert. In diesem Fall geht es schief weil innerhalb der vorhandenen Funktionen andere Funktionen aufgerufen werden die dir schlichtweg fehlen.

    Speicher die gesammte Datei in x:\Programme\Autoit3\Include ab dann klappt's auch mit dem Code im 2ten Block.

  • naja nur mit rüberkopieren geht es leider nicht.
    Was brauche ich statt #include "SysTray_UDF.au3" ?

  • Zitat

    naja nur mit rüberkopieren geht es leider nicht.
    Was brauche ich statt #include "SysTray_UDF.au3" ?

    Hast du mal getan was ich dort beschrieben habe? Scheinbar nicht.
    #include "SysTray_UDF.au3" bindet die Date in dein Skript ein. Steht der Dateiname zwischen " " sucht AutoIt im Skriptordner danach. Benutzt man stattdessen #include <datei.au3>, muss sie im Include Ordner liegen.

    Wenn du dir dann mal die komplette SysTray_UDF.au3 irgendwo ablegst wirst du sehen, das dein Skript ohne Fehlermeldung durchläuft. Ob es das tut was es soll ist eine andere Frage. Auf Win7 klappt das z.B. auf diese Weise nicht.

  • ok schon mal danke für eure antworten

    Ich bräuchte es aber für windows 7 gibts da ne andere möglichkeit?

  • Versteckt alle Icons bis ESC gedrückt wird.

    Spoiler anzeigen
    [autoit]

    #include <GuiToolBar.au3>
    HotKeySet("{ESC}", "_exit")
    Opt("WinTitleMatchMode", 4)
    $tray = WinGetHandle("[CLASS:Shell_TrayWnd]")
    $toolbar = ControlGetHandle($tray, "", "[CLASSNN:ToolbarWindow321]")
    $count = _GUICtrlToolbar_ButtonCount($toolbar)
    ConsoleWrite("Es gibt " & $count & " Icons im Tray" & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To $count - 1
    $commandID = _GUICtrlToolbar_IndexToCommand($toolbar, $i)
    $title = _GUICtrlToolbar_GetButtonText($toolbar, $commandID)
    ConsoleWrite("Index_" & $i & " " & @TAB & " CommandID_" & $commandID & @TAB & " Titel: " & $title & @CRLF)
    _GUICtrlToolbar_SetButtonState($toolbar, $commandID, $TBSTATE_HIDDEN)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    For $i = 0 To $count - 1
    $commandID = _GUICtrlToolbar_IndexToCommand($toolbar, $i)
    $title = _GUICtrlToolbar_GetButtonText($toolbar, $commandID)
    _GUICtrlToolbar_SetButtonState($toolbar, $commandID, $TBSTATE_ENABLED)
    Next
    Exit
    EndFunc ;==>_exit

    [/autoit]
  • Ist es damit auch möglich einzelne auszublenden? Wenn ich dieses script ausführe werden zwar alle icons versteckt aber der platz wird trotzdem noch eingenommen. Gibt es vll eine möglichkeit das icon ganz zu verstecken?

  • Du musst dir die Funktionen in so einem Skript schon anschauen, sonst wird das nichts. Dafür gibt es die Hilfe.

    _GUICtrlToolbar_SetButtonState($toolbar, $commandID, $TBSTATE_HIDDEN) versteckt die Icons. Die Betonung liegt hier auf "versteckt". Das bedeutet nicht, das dadurch Platz in der Toolbar frei wird.

  • ich habe jetzt in dieser _GUICtrlToolbar nachgeschaut aber leider nichts gefunden um ein icon ganz verschwinden zu lassen. (ohne ein leeres feld zu hinterlassen) Ist das unter win 7 überhaupt möglich?