Ver Mensaje Individual
  #45  
Antiguo 27-05-2016
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Reputación: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Mira este ejemplo en el que un Timer se encarga de dar notificaciones cada 10 segundos:

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ShellAPI;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TNotifyIconData = record
    cbSize: DWORD;
    Wnd: HWND;
    uID: UINT;
    uFlags: UINT;
    uCallbackMessage: UINT;
    hIcon: HICON;
    szTip: array [0..127] of AnsiChar;
    dwState: DWORD;
    dwStateMask: DWORD;
    szInfo: array [0..255] of AnsiChar;
    uTimeout: UINT;
    szInfoTitle: array [0..63] of AnsiChar;
    dwInfoFlags: DWORD;
  end;

// Ampliaciones para Vista
const NIIF_INFO    = $00000001;
const NIF_INFO     = $00000010;
const NIF_REALTIME = $00000040;
const NIF_SHOWTIP  = $00000080;
const NIIF_USER    = $00000004;


var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure ShowBalloon(Handle: THANDLE; Titulo, Texto: String);
var
  Data: TNotifyIconData;
begin
  ZeroMemory(@Data, sizeof(TNotifyIconData));
  Data.cbSize:= sizeof(TNotifyIconData);
  Data.uFlags:= NIF_ICON or NIF_INFO or NIF_REALTIME;
  Data.dwInfoFlags:= NIIF_INFO;
  lstrcpyn(Data.szInfoTitle, PCHAR(Titulo), 64-1);
  lstrcpyn(Data.szInfo, PCHAR(Texto), 256-1);
  Data.uTimeOut:= 1000;
  Data.Wnd:=  Handle;
  Shell_NotifyIcon(NIM_ADD, @Data);
  Shell_NotifyIcon(NIM_MODIFY, @Data);
  //Shell_NotifyIcon(NIM_DELETE, @Data);  // Para WinXp esta línea debe ser comentada. En el resto de S.O. también funciona con la línea comentada
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Application.ShowMainForm:= False;
 Timer1.Interval:= 10000;
 ShowBalloon(Handle, 'Comenzamos', 'Esto es una prueba');
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  ShowBalloon(Handle, 'Timer', 'Esto es una prueba');
end;

end.

Saludos.
Responder Con Cita