{------------------------------------------------- -------------------------------}
{Nome da unidade: trayicon.pas/t/t/t/t/t/t/t}
{/t/t/t/t/t/t/t/t/t/t/t/t}
{Autor da unidade: SaveTime ([email protected], http://savetime.delphhibbs.com)}
{Data criada: 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}
{Função Introdução:/t/t/t/t/t/t/t/t/t}
{Encapsular a maioria das funções do shell_notifyicon e adicione alguns aplicativos comuns /t /t}
{/t/t/t/t/t/t/t/t/t/t/t/t}
{Instruções para uso:/t/t/t/t/t/t/t/t}
{Se o evento OndblClick estiver definido, o tempo de resposta do OnClick aumentará o GetDoubleClicktime.
{Caso contrário, OnClick será executado imediatamente./t/t/t/t/t/t}
{Se o ícone não estiver definido, o ícone do aplicativo será usado./t/t/t}
{/t/t/t/t/t/t/t/t/t/t/t/t}
{Atualizar histórico:/t/t/t/t/t/t/t/t/t}
{Quando o clique com o botão direito do mouse aparece, clicando em outro local não pode fechar o menu.
{Add: SetForeRoundWindow (FWindow);
{/t/t/t/t/t/t/t/t/t/t/t/t}
{Problemas existentes:/t/t/t/t/t/t/t/t/t}
{Por enquanto, apenas o estilo Win95 Shell é suportado e a nova função da versão 5.0 é adicionada a /t /t posterior}
{O tempo de intervalo DoubleClick deve ser atualizado conforme as configurações do sistema mudam./t/t/t}
{Ao clicar em Trayicon, você deve definir se deve trazer o aplicativo para o primeiro plano./t/t/t}
{/t/t/t/t/t/t/t/t/t/t/t/t}
{------------------------------------------------- -------------------------------}
unidade trayicon;
interface
usa sysutils, classes, gráficos, controles, janelas, mensagens, formulários, menus,
Extctrls, shellapi;
tipo
// ================================================= ==========================================
// Classe Ttrayicon
// ================================================= ==========================================
TTrayicon = classe (TComponent)
Privado
Fwindow: hwnd;
Fhint: string;
Ficon: Ticon;
Factiva: Booleano;
FONCLICK: tnotifyEvent;
FondblClick: tnotifyEvent;
FPOPUPMENU: TPOPUPMENU;
FCLICKTIMER: TTIMER;
Ficondata: tnotifyicondata;
Procedimento CheckClickTimer (remetente: Tobject);
Procedimento SendTrayMessage (msgid: dWord; sinalizadores: uint);
Procedimento TrayWndProc (VAR Mensagem: TMessage);
Procedimento setActive (const Value: boolean);
Procedimento Seticon (Valor const: Ticon);
procedimento sethint (const valor: string);
Procedimento setPopupMenu (Valor const: tpopupMenu);
protegido
procedimento carregado;
Notificação do procedimento (Acomponente: TComponent; operação: toqueração);
público
Construtor Create (Anowner: TComponent);
destruidor destruir;
publicado
Propriedade Ativa: Boolean Leia a Factive Write SetActive padrão False;
Dica de propriedade: string leia fhint write sethint;
Ícone da propriedade: Ticon leia Ficon Write Seticon;
Propriedade popupmenu: tpopupmenu leia fpopupmenu write setPopupMenu;
Propriedade OnClick: tnotifyEvent leia FoNClick Write FonClick;
Propriedade ondblClick: tnotifyEvent leu fondbllick write fondbllick;
fim;
registro de procedimentos;
Implementação
registro de procedimentos;
Começar
RegisterComponents ('' SaveTime '', [tTrayicon]);
fim;
{Ttrayicon}
const
Wm_callbackmessage = wm_user + 100;
procedimento ttrayicon.checkClicktimer (remetente: tabjas);
Começar
Fclicktimer.enabled: = false;
se atribuído (fonclick), então foneClick (self);
fim;
construtor ttrayicon.create (awner: tComponent);
Começar
Criar Herited (AOWNER);
Fwindow: = classes.allocatehwnd (baywndproc);
FICON: = ticon.create;
Fclicktimer: = ttimer.create (self);/t // timer que lida com intervalos de clique e clique duas vezes
Fclicktimer.enabled: = false;
FClicktimer.Interval: = getDoubleClicktime;
Fclicktimer.ontimer: = checkClicktimer;
Ficondata.cbsize: = sizeof (ficondata);/t // inicialize a estrutura notificada
Ficondata.Wnd: = fwindow;
Ficondata.uid: = uint (self);
Ficondata.ucallbackMessage: = wm_callbackmessage;
fim;
destruidor ttrayicon.destroy;
Começar
Ativo: = false;
Fclicktimer.free;
Ficon.Free;
Classes.DealLocatehwnd (fwindow);
herdado;
fim;
procedimento ttrayicon.loaded;
Começar
herdado;
Se a Factiva então
SendTrayMessage (nim_add, nif_message ou nif_icon ou nif_tip);
fim;
procedimento ttrayicon.Notification (Acomponente: TComponent; operação: toqueração);
Começar
notificação herdada (acomponente, operação);
if (operação = opremove) e (acomponent = popupmenu) então
Popupmenu: = nil;
fim;
procedimento ttrayicon.sendtrayMessage (msgid: dword; sinalizadores: uint);
Começar
if (sinalizadores e nif_icon) <> 0 então
Começar
Se Ficon.Handle = 0 então/t/t // se o ícone não estiver definido, use o ícone padrão
Ficondata.hicon: = Application.icon.handle
outro
Ficondata.hicon: = ficon.handle;
fim;
Ficondata.uflags: = sinalizadores;
Shell_notifyicon (msgid, @FICONDATA);
fim;
procedimento tTrayicon.SetActive (Valor const: booleano);
Começar
Factive: = Value;
se (não (csdesigning no componentState)) e
(não (csloading no componentState)) então
Começar
Se o valor então
SendTrayMessage (NIM_ADD, NIF_MESSAGE ou NIF_ICON ou NIF_TIP)
outro
SendTrayMessage (nim_delete, 0)
fim;
fim;
procedimento ttrayicon.sethint (const valor: string);
Começar
Fhint: = value;
StrPlcopy (ficondata.sztip, pchar (fhint), sizeof (ficondata.sztip));
se (não (csdesigning no componentState)) e
(não (csloading no componentState)) e
Factiva então
Começar
SendTrayMessage (nim_modify, nif_tip);
fim;
fim;
procedimento ttrayicon.seticon (valor const: ticon);
Começar
Ficon.assign (valor);
Se (Factive e não (csdesigning no componentState)) então
SendTrayMessage (nim_modify, nif_icon);
fim;
procedimento ttrayicon.setPopupMenu (Valor const: tpopupmenu);
Começar
FpopupMenu: = value;
se valor <> nil então value.freenotification (self);
fim;
procedimento tTrayicon.TrayWndProc (VAR Message: tMessage);
var
Pt: tpoint;
Começar
com a mensagem
Começar
Se msg = wm_callbackmessage então
Começar
caso lparam of
/twm_lbuttondown:
/tbegin
/t // Se o evento OndblClick não estiver definido, ligue diretamente onclick
/t se não for atribuído (fondblcick) então
/t comece
/t Se atribuído (Fonclick), então foneClick (self);
/tratar
/t elim
/t fclicktimer.enabled: = true;
/tratar;
/twm_lbuttondblclk:
/tbegin
/t fclicktimer.enabled: = false;
/t se atribuído (fondblClick) e fondebllick (self);
/tratar;
/twm_rbuttondown:
/tbegin
/t se atribuído (fpopupmenu) então
/t comece
/t setForegroundwindow (fwindow);
/t getCursorPos (pt);
/t fpopupmenu.popup (pt.x, pt.y);
/tratar;
/tratar;
fim;
fim
else // Outras mensagens são entregues ao Windows para processamento
Resultado: = DEFWindowProc (fwindow, msg, wparam, lparam);
fim;
fim;
fim.