{------------------------------------------------- -----------------------------}
{Nom de l'unité: Trayicon.pas / t / t / t / t / t / t / t}
{/ t / t / t / t / t / t / t / t / t / t / t / t}
{Unité Auteur: Savetime ([email protected], http://savetime.delphhibbs.com)}
{Date de création: 2004-11-13 12: 20: 54 / T / T / T / T / T / T / T}
{/ t / t / t / t / t / t / t / t / t / t / t / t}
{Fonction introduction: / t / t / t / t / t / t / t / t / t}
{Encapsuler la plupart des fonctions de shell_notifyicon et ajouter des applications communes / t / t}
{/ t / t / t / t / t / t / t / t / t / t / t / t}
{Instructions pour une utilisation: / t / t / t / t / t / t / t / t}
{Si l'événement ondblclick est défini, le temps de réponse d'Onclick augmentera GetDoubleClicktime.
{Sinon, onClick sera exécuté immédiatement./t/t/t/t/t/t/t}
{Si l'icône n'est pas définie, l'icône d'application sera utilisée./t/t/t}
{/ t / t / t / t / t / t / t / t / t / t / t / t}
{Historique de mise à jour: / t / t / t / t / t / t / t / t / t}
{Lorsque le menu à clic droit apparaît, en cliquant sur un autre emplacement ne peut pas fermer le menu.
{Add: SetforegroundWindow (fwindow); avant que le menu contextuel ne soit affiché./t/t}
{/ t / t / t / t / t / t / t / t / t / t / t / t}
{Problèmes existants: / t / t / t / t / t / t / t / t / t}
{Pour le moment, seul le style de shell Win95 est pris en charge, et la nouvelle fonction de version 5.0 est ajoutée à / t / t plus tard}
{Le temps d'intervalle de doublure doit être mis à jour à mesure que les paramètres du système modifient./t/t/t}
{Lorsque vous cliquez sur TrayIcon, vous devez définir l'opportunité d'apporter l'application au premier plan./t/t/t}
{/ t / t / t / t / t / t / t / t / t / t / t / t}
{------------------------------------------------- -----------------------------}
Trayicon d'unité;
interface
utilise des synutils, des classes, des graphiques, des contrôles, des fenêtres, des messages, des formulaires, des menus,
Extctrls, shellapi;
taper
// =============================================================. =======================================================.
// classe ttrayicon
// =============================================================. =======================================================.
TtRayIcon = class (tComponent)
Privé
Fwindow: hwnd;
Fhint: string;
Ficon: Ticon;
Factation: Boolean;
FonClick: tnotifyEvent;
Fondblclick: tnotifyEvent;
Fpopupmenu: tpopupmenu;
Fclicktimer: Ttimer;
Ficondata: tnotifyicondata;
Procédure CheckClicktimer (expéditeur: tobject);
Procédure SendTrayMessage (MSGID: DWORD; Flags: UInt);
Procédure TraywndDProc (message VAR: TMessage);
Procédure setactive (constamment de const: booléen);
Procédure SETICON (const Value: Ticon);
Procédure SetHint (const Value: String);
Procédure setPopupMenu (constamment de const: tpopupMenu);
protégé
procédure chargée;
Notification de procédure (Acomponent: TComponent; Opération: Topration);
publique
Conclusion Create (Aowner: TCOMPONont);
Destructor détruire;
publié
Propriété active: Boolean Read Factative Write Setactive Default False;
Astuce de la propriété: String Read Fhint Write SetHint;
Icône de la propriété: Ticon Read Ficon Write Seticon;
Property PopupMenu: TpopupMenu Lire fpopupMenu Write SetPopupMenu;
Property onclick: tnotifyEvent read Fonclick Write Fonclick;
propriété ondblclick: tnotifyEvent read Fondblclick écriture fondblick;
fin;
Registre de procédure;
Mise en œuvre
Registre de procédure;
Commencer
RegisterComponents ('' Savetime '', [TTRAYICON]);
fin;
{Ttrayicon}
const
WM_CALLBACKMESSAGE = WM_USER + 100;
Procédure ttRayIcon.CheckClicktimer (expéditeur: tobject);
Commencer
Fclicktimer.enabled: = false;
si elle est affectée (FonClick) alors FonClick (self);
fin;
constructeur ttRayIcon.Create (aowner: tComponent);
Commencer
hérité de création (aowner);
Fwindow: = classes.ALLOCOTHWND (TraywndProc);
Ficon: = Ticon.Create;
Fclicktimer: = ttimemer.create (self); / t // minuterie qui gère les intervalles de clic et de double-cliquez
Fclicktimer.enabled: = false;
Fclicktimer.interval: = getDoubleClicktime;
Fclicktimer.onmer: = checkClicktimer;
Ficondata.cbSize: = sizeof (ficondata); / t // initialisez la structure de notifyIcondata
Ficondata.wnd: = fwindow;
Ficondata.uid: = uint (self);
Ficondata.ucallbackMessage: = wm_callbackMessage;
fin;
destructor ttrayicon.destroy;
Commencer
Actif: = false;
Fclicktimer.free;
FICON.FREE;
Classes.dealLocateHwnd (fwindow);
hérité;
fin;
procédure ttrayicon.loadée;
Commencer
hérité;
Si factif alors
SendTrayMessage (NIM_ADD, NIF_MESSAGE ou NIF_ICON ou NIF_TIP);
fin;
Procédure ttRayIcon.Notification (Acomponent: TComponent; Opération: Topration);
Commencer
notification héritée (acomponent, opération);
if (operation = OpreMove) et (Acomponent = PopupMenu) alors
PopupMenu: = NIL;
fin;
Procédure ttRayIcon.SendTrayMessage (msgid: DWORD; Flags: uint);
Commencer
if (drapeaux et nif_icon) <> 0 alors
Commencer
Si ficon.handle = 0 alors / t / t // Si l'icône n'est pas définie, utilisez l'icône par défaut
Ficondata.hicon: = application.icon.handle
autre
Ficondata.hicon: = Ficon.handle;
fin;
Ficondata.uflags: = drapeaux;
Shell_NotifyIcon (msgid, @ficondata);
fin;
Procédure ttRayIcon.SetActive (constamment de const: boolean);
Commencer
Factation: = valeur;
if (pas (csdesigning dans composantState)) et
(pas (CSloading dans ComponentState)) puis
Commencer
Si la valeur alors
SendTrayMessage (NIM_ADD, NIF_MESSAGE ou NIF_ICON ou NIF_TIP)
autre
SendTrayMessage (NIM_DELETE, 0)
fin;
fin;
Procédure ttRayIcon.SethInt (const Value: String);
Commencer
Fhint: = valeur;
StrplCopy (ficondata.sztip, phar (fhint), sizeof (ficondata.sztip));
if (pas (csdesigning dans composantState)) et
(pas (csloading dans composantState)) et
Factif alors
Commencer
SendTrayMessage (NIM_MODIFY, NIF_TIP);
fin;
fin;
Procédure TTRAYICON.SETION (constamment de const: Ticon);
Commencer
FICON.Assign (valeur);
if (factative et non (Csdesigning dans ComponentState)) alors
SendTrayMessage (NIM_MODIFY, NIF_ICON);
fin;
Procédure ttRayIcon.SetPopupMenu (Valeur const: tpopupMenu);
Commencer
FpopupMenu: = valeur;
Si valeur <> nil alors valeur.freenotification (self);
fin;
Procédure ttRayIcon.traywndproc (message var: tMessage);
var
PT: TPoint;
Commencer
avec un message faire
Commencer
Si msg = wm_callbackMessage alors
Commencer
cas lparam de
/ twm_lbuttondown:
/ tbegin
/ t // Si l'événement ondblclick n'est pas défini, appelez ONClick directement
/ t si ce n'est pas affecté (Fondblclick) puis
/ T commence
/ t si attribué (FonClick) puis FonClick (self);
/tendre
/ T else // Sinon, utilisez du temps pour déterminer si le temps de double cliquez
/ t fclicktimer.enabled: = true;
/tendre;
/ twm_lbuttondblclk:
/ tbegin
/ t fclicktimer.enabled: = false;
/ t si elle est affectée (fondblclick) puis fondblclick (self);
/tendre;
/ twm_rbuttondown:
/ tbegin
/ t si attribué (fpopupMenu) puis
/ T commence
/ t SetforegroundWindow (fwindow);
/ t getCursorpos (pt);
/ t fpopupmenu.popup (pt.x, pt.y);
/tendre;
/tendre;
fin;
fin
else // D'autres messages sont transmis à Windows pour le traitement
Résultat: = defwindowProc (Fwindow, Msg, Wparam, Lparam);
fin;
fin;
fin.