Difference between revisions of "TrayIcon/de"
Line 162: | Line 162: | ||
Zu finden unter components/trayicon/ im aktuellen Subversion-Verzeichnis | Zu finden unter components/trayicon/ im aktuellen Subversion-Verzeichnis | ||
− | === | + | === Hilfe, Bugreports und Funktionswünsche === |
− | + | Bitte stellen sie Bugreports und Funktionswünsche im [http://www.lazarus.freepascal.org/mantis/main_page.php Lazarus Bugtracker]. | |
− | + | Hilfsanfragen können in der Lazarus-Maillinglist oder im [http://www.lazarus.freepascal.org/modules.php?op=modload&name=PNphpBB2&file=index Forum] gestellt werden. | |
=== Change Log === | === Change Log === |
Revision as of 21:33, 7 February 2007
About
TrayIcon ist eine crossplattformtaugliche Systemtray-Komponente, welche momentan unter folgenden Widgetsets funktioniert: win32, Gtk1, Gnome, Gtk2. Für die Zukunft ist außerdem Carbon ( Mac OS X ) und Qt 4 vorgesehen.
Zwei Schnittstellen werden momentan angeboten: eine visuelle Koponente und ein non-visuelles Objekt. Zweiteres heißt SystrayIcon und ist delphikompatibel. Die visuelle Komponente ist das TTrayIcon, welches nur mit Lazarus funktioniert.
Als Schnelleinstieg siehe: das Demonstrationsprogram.
Dokumentation
Nachfolgend eine Liste mit allen Methoden, Properties und Events, welche die Komponente zur Verfügung stellt. Namen und Funktion sind für die visuelle und die nicht-visuelle Version identisch. Außerdem arbeiten die Funktionen, außer wenn anders angegeben unter allen Plattformen.
Methoden
Show
procedure Show;
Zeigt das Icon im Systemtray
Hide
procedure Hide;
Entfernt das Icon aus dem Systemtray
GetPosition
function GetPosition: TPoint;
Gibt die Position des Trayicons auf dem Bildschirm aus. Diese Funktion dient dazu, Nachrichten nahe des Icons anzuzeigen. Dies ist allerdings momentan nur ein Platzhalter und nicht implementiert. Stattdessen wird immer der Punkt (0, 0) zurückgegeben.
Properties
Hint
property Hint: string;
ShowHint
property ShowHint: Boolean;
PopUpMenu
property PopUpMenu: TPopUpMenu;
Gibt ein Popupmenu an, welches bei Rechtsklick auf das Icon erscheint.
Events
OnPaint
property OnPaint: TNotifyEvent;
Erlaubt eine eigene Zeichenroutine für das Canvas des Icons.
Bemerkung: Arbeitet nicht unter Win32!
OnClick
property OnClick: TNotifyEvent;
OnDblClick
property OnDblClick: TNotifyEvent;
OnMouseDown
property OnMouseDown: TMouseEvent;
OnMouseUp
property OnMouseUp: TMouseEvent;
OnMouseMove
property OnMouseMove: TMouseMoveEvent;
Screenshot
Autoren
Lizenz
Modifizierte LGPL
Download
Status: Stable
Ist bei jeder aktuellen Lazarusinstallation im Ordner lazarus/components/trayicon zu finden.
Installation
Demonstartionsprogram
Dieses Programm läd ein Icon aus einer internen Ressource (unter Windows) bzw. aus einer externen datei (unter anderen Plattformen als Windows).
Um die Ressource mit dem Icon unter Windows zu erstellen und einzubinden ist folgendes nötig:
1. Erstellen sie ein Ressourcenskript traytest.rc wie dieses:
101 ICON "icon1.ico"
2. Compilieren sie das Ressourcenskript mittels windres.exe in eine *.res Datei. (Windres ist im Lazarusverzeichnis zu finden) Der Befehl lautet: windres -i traytest.rc -o traytest.res
Nu können sie ihr testprogramm schreiben. Erstellen sie eine neue Anwendung mit einem Formular und fügen sie in die entsprechende Unit folgendes in den Interface-Abschnitt ein:
{$ifdef win32} {$R traytest.res} {$endif}
Als nächste benötigen sie noch einen Button. Schreiben sie folgendes in das OnClick-Event des Buttons:
procedure MyForm.Button1Click(Sender: TObject); const IDI_ICON1 = 101; begin {$ifdef win32} SystrayIcon.Icon.Handle := LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); //7. März 2006 - Das laden einer .ico-Datei unter Windows funktioniert nicht {$else} SystrayIcon.Icon.LoadFromFile('/path_to_icon/icon.ico'); //7. März 2006 - Es kann zu Problemen mit der Darstellung von .ico-Dateien kommen. //Ist dies der Fall, probieren sie xpm (dies löst das Problem unter FedoraCore 4 / Gnome) {$endif} SystrayIcon.ShowHint := True; SystrayIcon.Hint := 'Mein Tooltip'; SystrayIcon.PopUpMenu := MyPopUpMenu; SystrayIcon.Show; end;
Subversion
Zu finden unter components/trayicon/ im aktuellen Subversion-Verzeichnis
Hilfe, Bugreports und Funktionswünsche
Bitte stellen sie Bugreports und Funktionswünsche im Lazarus Bugtracker.
Hilfsanfragen können in der Lazarus-Maillinglist oder im Forum gestellt werden.
Change Log
- 17/01/2006 - Available as a preview on the Lazarus subversion. Still under heavy construction, however.
- 24/01/2006 - Stable under win32, gnome and gtk1, but still waiting for gtk2 support. Lazarus 0.9.12 was release with this version.
- 17/02/2006 - Added support for gtk2 on subversion.
Technical Details
A difficulty on the development of this component was the many differences on the system tray implementation on varios OSes and even Window Managers on Linux. To solve this, the component tryes to implement the minimal set of features common to all target platforms. Bellow is a list of the features implemented on each platform:
Windows - Multiple system tray icons per application are supported. The image of the icon can be alterred using a HICON handle. Events to the icon are sent via a special message on the user reserved space of messages (>= WM_USER) to the Window which owns the Icon. No paint events are sent to the Window.
Linux (Gnome, KDE, IceWM, etc) - Multiple system tray icons per application are supported. The image of the icon is acctually a very small Window, and can be painted and receive events just like any other TForm descendent.
Linux (WindowMaker, Openbox, etc) - Does not support system tray icons out-of-the-box. However, There are at least two softwares that provides support for it: Docker and WMSystray
Mac OS X - This system doesn´t really have System Tray icons in the way Linux and Windows have them. This component attempts to use tray-like features of Mac OS X to implement a tray icon. Every application on Mac OS X has a Dock icon. The software can assign a popup menu for this Dock, and this is probably how TrayIcon for Mac OS will work in the future. One compatibility problem is that only one Dock per application can exist.
You can see here is how it will look like: http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGMenus/chapter_16_section_6.html
With this in mind a approach which supports all Platforms was created:
- Only one Systray Icon is supported per application, and all applications that use the component have it initialized on the startup of the program. This way you will use the SystrayIcon object, and not it´s class. (Required by Mac OS X)
- Painting is done via a TIcon object. (Required by Windows)
The following extra features are already available or will be, but they won´t work on all platforms.
- Multiple Systray Icons. Won´t work on Mac OS X.
- OnPaint event and Canvas property to draw the icon freely. Won´t work on Windows.
External Links
- http://www.codeproject.com/shell/ctrayiconposition.asp - Code and theory to find the tray icon position under Windows
- http://cvs.gnome.org/viewcvs/gtk%2B/gtk/gtkstatusicon.c?rev=1.23&view=markup - Gtk2 code that implements gtkstatusicon