{------------------------------------------------- -----------------------------}
{Nombre de la unidad: Trayicon.pas/t/t/t/t/t/t/t}
{/t/t/t/t/t/t/t/t/t/t/t/t/t}
{Autor de la unidad: SaveTime ([email protected], http://savetime.delphhibbs.com)}
{Fecha creada: 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/t}
{Función Introducción:/t/t/t/t/t/t/t/t/t/t}
{Encapsular la mayoría de las funciones de shell_notifyicon y agregar algunas aplicaciones comunes /t /t}
{/t/t/t/t/t/t/t/t/t/t/t/t/t}
{Instrucciones para usar:/t/t/t/t/t/t/t/t/t}
{Si se establece el evento OnDBlick, el tiempo de respuesta de OnClick aumentará GetDoubleclickTime.
{De lo contrario, OnClick se ejecutará inmediatamente ./t/t/t/t/t/t/t}
{Si el icono no está configurado, se usará el icono de la aplicación ./t/t/t}
{/t/t/t/t/t/t/t/t/t/t/t/t/t}
{Historial de actualizaciones:/t/t/t/t/t/t/t/t/t/t}
{Cuando aparece el menú de clic derecho, hacer clic en otra ubicación no puede cerrar el menú.
{Agregar: setForegroundWindow (fwindow);
{/t/t/t/t/t/t/t/t/t/t/t/t/t}
{Problemas existentes:/t/t/t/t/t/t/t/t/t}
{Por el momento, solo se admite el estilo de shell Win95, y la nueva función de la versión 5.0 se agrega a /t /t más tarde}
{El tiempo de intervalo de DoubleClick debe actualizarse a medida que cambie la configuración del sistema ./t/t/t}
{Al hacer clic en Trayicon, debe establecer si debe llevar la aplicación al primer plano ./t/t/t}
{/t/t/t/t/t/t/t/t/t/t/t/t/t}
{------------------------------------------------- -----------------------------}
Unidad de Trayicon;
interfaz
utiliza sysutils, clases, gráficos, controles, ventanas, mensajes, formularios, menús,
Extctrls, shellapi;
tipo
// =================================================== ==========================================
// clase ttrayicon
// =================================================== ==========================================
Ttrayicon = class (tcomponent)
Privado
Fwindow: hwnd;
Fhint: cadena;
Ficon: Ticon;
Factive: booleano;
Fonclick: tnotifyEvent;
FondblClick: tnotifyEvent;
Fpopupmenu: tpopupmenu;
FClickTimer: ttimer;
Ficondata: tnotifyicondata;
procedimiento checkclicktimer (remitente: tobject);
procedimiento sendTrayMessage (msgid: dword; flags: uint);
Procedimiento TraywnDProc (Mensaje VAR: TMessage);
procedimiento setActive (valor const: booleano);
procedimiento Seticon (valor const: ticon);
procedimiento sethint (constante const: cadena);
procedimiento setPopupMenu (valor const: tpopupmenu);
protegido
procedimiento cargado;
Notificación del procedimiento (cájaro: TComponente; operación: topación);
público
constructor create (downer: tcomponent);
Destructor destruir;
publicado
Propiedad activa: Boolean Read Factive Write SetActive predeterminado falso;
Propiedad Sugerencia: cadena Leer fhint escribir sethint;
Icono de la propiedad: Ticon Read Ficon Write Seticon;
PROPIEDAD POBUPMENU: tpopupmenu lea fpopupmenu escribir setPopupMenu;
Propiedad OnClick: tnotifyEvent lea fonclick escribir fonclick;
Propiedad OndblClick: tnotifyEvent lea fondblClick escribir fondblclick;
fin;
registro de procedimientos;
Implementación
registro de procedimientos;
Comenzar
RegisterComponents ('' SaveTime '', [tTrayiCon]);
fin;
{Ttrayicon}
estúpido
Wm_callbackmessage = wm_user + 100;
procedimiento tTrayicon.CheckClickTimer (remitente: tobject);
Comenzar
FClickTimer.enabled: = false;
si se asigna (fonclick) entonces fonclick (self);
fin;
constructor ttrayicon.create (Awner: tcomponent);
Comenzar
creación hereditaria (un downer);
Fwindow: = classes.AllOdHwnd (TrayWndProc);
Ficon: = ticon.create;
Fclicktimer: = ttimer.create (self);/t // temporizador que maneja los intervalos de clic y doble clic
FClickTimer.enabled: = false;
FClickTimer.interval: = getDoubleclicktime;
FClickTimer.ontimer: = checkclicktimer;
Ficondata.cbsize: = sizeof (ficondata);/t // Inicializar la estructura Notifyicondata
Ficondata.wnd: = fwindow;
Ficondata.uid: = uint (self);
Ficondata.ucallbackMessage: = wm_callbackMessage;
fin;
destructor ttrayicon.destroy;
Comenzar
Activo: = falso;
FClickTimer.Free;
Ficon.
Classes.deallocateHwnd (fwindow);
heredado;
fin;
procedimiento ttrayiCon.loaded;
Comenzar
heredado;
Si de hecho entonces entonces
SendTrayMessage (NIM_ADD, NIF_MESSAGE o NIF_ICON o NIF_TIP);
fin;
procedimiento ttrayicon.notificación (cájaro: tcomponent; operación: topación);
Comenzar
Notificación hereditaria (cájaro, operación);
if (operation = opremove) y (conponente = popupmenu) entonces
Popupmenu: = nil;
fin;
procedimiento ttrayicon.sendTrayMessage (msgid: dword; banderas: uint);
Comenzar
if (flags y nif_icon) <> 0 entonces
Comenzar
Si ficon.handle = 0 entonces/t/t // Si el icono no está configurado, use el icono predeterminado
Ficondata.hicon: = Application.icon.handle
demás
Ficondata.hicon: = ficon.handle;
fin;
Ficondata.Uflags: = flags;
Shell_notifyicon (msgid, @FiFonData);
fin;
procedimiento ttrayicon.setActive (valor const: booleano);
Comenzar
Factive: = valor;
if (no (csdesigning in componentstate)) y
(no (csloading en componentstate)) entonces
Comenzar
Si el valor entonces
SendTrayMessage (NIM_ADD, NIF_MESSAGE o NIF_ICON o NIF_TIP)
demás
SendTrayMessage (NIM_DELETE, 0)
fin;
fin;
procedimiento ttrayicon.sethint (valor const: string);
Comenzar
Fhint: = valor;
StrplCopy (ficondata.sztip, pchar (fhint), sizeOf (ficondata.sztip));
if (no (csdesigning in componentstate)) y
(no (csloading en componentstate)) y
De hecho entonces
Comenzar
SendTrayMessage (nim_modify, nif_tip);
fin;
fin;
procedimiento ttrayicon.Seticon (valor const: ticon);
Comenzar
Ficon.assign (valor);
if (factive y no (csdesigning in componentstate)) entonces
SendTrayMessage (NIM_MODIFY, NIF_ICON);
fin;
procedimiento ttrayicon.setPopupMenu (valor const: tpopupmenu);
Comenzar
Fpopupmenu: = valor;
if value <> nil entonces value.freenotificación (self);
fin;
procedimiento ttrayicon.TraywnDProc (Mensaje var: tMessage);
varilla
Pt: tpoint;
Comenzar
con mensaje hacer
Comenzar
Si msg = wm_callbackMessage entonces
Comenzar
Caso Lparam de
/twm_lbuttondown:
/tbegin
/t // Si el evento OndblClick no está configurado, llame a OnClick directamente
/t si no se asigna (fondblClick) entonces
/t comienza
/t si se le asigna (fonclick) entonces fonclick (self);
/tender
/t else // de lo contrario, use tiempo para determinar si el tiempo de doble clic ha alcanzado
/t fclicktimer.enabled: = true;
/tender;
/twm_lbuttondblclk:
/tbegin
/t fclicktimer.enabled: = false;
/t si se le asigna (FondblClick) entonces FondblClick (self);
/tender;
/twm_rbuttondown:
/tbegin
/t si se asigna (fpopupmenu) entonces
/t comienza
/t setForegroundwindow (fwindow);
/t getCursorpos (PT);
/t fpopupmenu.popup (pt.x, pt.y);
/tender;
/tender;
fin;
fin
else // se entregan otros mensajes a Windows para su procesamiento
Resultado: = defwindowproc (fwindow, msg, wparam, lparam);
fin;
fin;
fin.