Ver Mensaje Individual
  #1  
Antiguo 30-06-2006
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.286
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Icono en la barra de tareas (Tray)

Cómo colgar un icono en la barra de tareas mediante código.

Aunque pueda resultar más engorroso, colgar el icono de nuestra aplicación en la barra de tareas mediante código no tiene nada de dificil. Tan solo hay que preveer que tal icono necesitará comunicarse con nuestra aplicación mediante un mensaje windows de aviso ante eventos y del icono que queramos colgar.

Previamente deberemos definir el identificador de nuestro mensaje y las variables necesarias :

Código Delphi [-]
const WM_ICONCLICKED = WM_USER + 100;
         NIM_ICON_ID    = 1;    // solo ponemos un icono
  
TForm1 = class( TForm )
  ...
  private
    NotifyInfo : TNotifyIconData;
    Procedure    IconClicked( Var Msg: TMessage ); Message WM_ICONCLICKED;

Y definir nuestro procediemiento :

Código Delphi [-]
procedure TForm1.ColgarIcono;
begin
  With NotifyInfo Do Begin
       cbSize := SizeOf(NotifyInfo);
       Wnd    := Handle;      // Ventana a la que se enviarán los mensajes
       uID    := NIM_ICON_ID; // Identificador del Icon en la barra
       uFlags := NIF_ICON Or NIF_MESSAGE Or NIF_TIP;
       uCallbackMessage := WM_CONCLICKED;     // Mensaje que deberá generar
       hIcon  := Icon.Handle;                 // Icono que se mostrará
       szTip  := 'Icono en su puesto';        // Texto indicativo
  end;
  Shell_NotifyIcon(NIM_ADD, @NotifyInfo);     // Añadir Icono
end;

Luego, en el momento deseado solo tendremos que llamar a ColgarIcono, mientras que para quitarlo deberemos hacer lo siguiente :

Código Delphi [-]
Shell_NotifyIcon(NIM_DELETE, @NotifyInfo); // Añadir Icono
Responder Con Cita