Systemtray icon mit Menü erzeugen

  • Salute,

    ich möchte gern ein Icon im Systemtray erzeugen..., mit Menü beim draufklicken.

    Hat irgendjemand 'ne Ahnung wie man das realisieren könnte... ?

    Oder kann ich gar das AutoIt Systemtray Icon umfunktionieren, so mit eigenem Icon und Kontextmenü... ? *Grübel*


    Wäre für jeden Tip dankbar !


    Greetz


  • Hi!

    Ein sehr schönes Beispiel hat der User Schneemann einmal gemacht.


    (also wie gesagt: Wurde von Schneemann geschrieben!)

    [autoit]

    #include <GuiConstants.au3>
    #include <Constants.au3>
    #include <Array.au3>

    ; license
    #comments-start
    WinKlipper - A program that backups your clipboard
    Copyright (C) 2006 Janosch Graef

    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
    #comments-end

    ; vars
    global $autostartkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
    global $cb
    global $lc = ClipGet()
    global $filename = @HomeDrive&"\clipboard.txt"
    global $traycb[10]
    global $cbb[10]
    global $autostart

    ; trayeventoptions
    func traycbevent($num)
    local $clip = $cbb[$num-1]
    if ($clip<>"") then ClipPut($clip)
    EndFunc
    dim $func
    func traycbevent1()
    traycbevent(1)
    endfunc
    func traycbevent2()
    traycbevent(2)
    endfunc
    func traycbevent3()
    traycbevent(3)
    endfunc
    func traycbevent4()
    traycbevent(4)
    endfunc
    func traycbevent5()
    traycbevent(5)
    endfunc
    func traycbevent6()
    traycbevent(6)
    endfunc
    func traycbevent7()
    traycbevent(7)
    endfunc
    func traycbevent8()
    traycbevent(8)
    endfunc
    func traycbevent9()
    traycbevent(9)
    endfunc
    func traycbevent10()
    traycbevent(10)
    endfunc

    ; tray hier beginnt der tray unten rechts
    TrayTip("WinKlipper","WinKlipper is running now."&@LF&"For infos right-click on the icon an then click on ""Infos"" "&@LF&"Have fun ;)",5)
    opt("TrayAutoPause",0)
    opt("TrayMenuMode",1)
    opt("TrayOnEventMode",1)
    TraySetClick(16) ; wenn rechtsklick...
    $tray_clipboard = TrayCreateMenu("Clipboard",-1,1)
    for $a=1 to 10 step 1
    $traycb[$a-1] = TrayCreateItem("<empty>",$tray_clipboard,$a)
    TrayItemSetOnEvent($traycb[$a-1],"traycbevent"&$a)
    next
    $tray_trenner1 = TrayCreateItem("",-1,2)
    $tray_infos = TrayCreateItem("Infos",-1,3)
    $tray_about = TrayCreateItem("About",-1,4)
    $tray_trenner2 = TrayCreateItem("",-1,5)
    global $tray_autostart = TrayCreateItem("Autostart",-1,6)
    if (RegRead($autostartkey,"winklipper")==@ScriptFullPath) then
    TrayItemSetState($tray_autostart,$TRAY_CHECKED)
    $autostart = TRUE
    Else
    TrayItemSetState($tray_autostart,$TRAY_UNCHECKED)
    $autostart = FALSE
    EndIf
    $tray_exit = TrayCreateItem("Exit",-1,7)
    TrayItemSetOnEvent($tray_infos,"infos")
    TrayItemSetOnEvent($tray_about,"about")
    TrayItemSetOnEvent($tray_autostart,"autostart")
    TrayItemSetOnEvent($tray_exit,"quit")

    ; functions
    func shorten($text)
    $suffix = 0
    $text = StringReplace($text,@LF,@CRLF)
    $text = StringReplace($text,@CR,@CRLF)
    $lines = StringSplit($text,@CRLF)
    if (UBound($lines)>2) Then
    $text = $lines[1]
    $suffix = 1
    EndIf
    if (StringLen($text)>64) Then
    $text = StringLeft($text,61)
    $suffix = 1
    endif
    $text = StringStripWS($text, 3)
    if ($suffix==1) then $text = $text&"..."
    return $text
    EndFunc
    func entry_add()
    FileWrite($filename,@MON&"/"&@MDAY&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&":"&@CRLF&$cb&@CRLF&"=========================================="&@CRLF)
    $lc = $cb
    for $a=8 to 0 step -1
    TrayItemSetText($traycb[$a+1],TrayItemGetText($traycb[$a]))
    $cbb[$a+1] = $cbb[$a]
    next
    $cbb[0] = $cb
    TrayItemSetText($traycb[0],shorten($cb))
    EndFunc
    func infos()
    MsgBox(64,"WinKlipper - Infos","WinKlipper will remember all your clipboard-entries in "&$filename&". To restore an clipboard-entry easylier right-click on the icon, move with the mouse over ""Clipboard"" and then click on the text you want to restore.")
    endfunc
    func about()
    MsgBox(64,"WinKlipper - About","WinKlipper"&@LF&@LF&"Version: 1.1 (beta)"&@LF&"Author: Janosch Grý"&@LF&"Website: https://autoit.de/www.winklipper.de.vu"&@LF&"License: GNU/GPL")
    endfunc
    func autostart()
    if ($autostart==FALSE) then
    RegWrite($autostartkey,"winklipper","REG_SZ",@ScriptFullPath)
    TrayItemSetState($tray_autostart,1)
    $autostart = TRUE
    Else
    RegDelete($autostartkey,"winklipper")
    TrayItemSetState($tray_autostart,4)
    $autostart = FALSE
    EndIf
    EndFunc
    func quit()
    exit
    EndFunc

    ; program
    FileDelete($filename)
    while TRUE
    $cb = ClipGet()
    if ($cb<>"") Then
    if ($cb<>$lc) Then
    entry_add()
    endif
    endif
    sleep(500)
    wend

    [/autoit]


    Ich hab dir noch ein paar comments reingegeben damit du dich im tray auskennst :-))


    Mfg


    Huggy

  • Vielen Dank, das sollte mir weiterhelfen ! =)


    Edit: Die ganzen "TrayIcon" finde ich in meiner Hilfe (Deutsche Übersetzung) nicht, da ist nur TrayTip, TrayIconHide und TrayIconDebug... :irre:


    2 Mal editiert, zuletzt von Greenhorn (28. Dezember 2006 um 15:51)