Ver Mensaje Individual
  #20  
Antiguo 18-01-2007
fide fide is offline
Miembro
 
Registrado: oct 2006
Posts: 331
Reputación: 18
fide Va por buen camino
Post Componente

Código Delphi [-]
 
  // Sepan que no estoy muy diestro en la creación de componentes pero me  atreví a hacer este con la ayuda de unos amigos una tarde de aurrimiento.
  

   
  //---------------------------------------------------------
   
  unit NotifyBalloon;
   
  interface
   
  uses
    SysUtils,Windows, Classes, ShellApi,Forms,Dialogs;
   
   
  const
     NIF_INFO = $10;
   
   
  type
    TNotifyIcons = (NIIF_NONE , NIIF_INFO ,NIIF_WARNING ,NIIF_ERROR ,NIIF_USER );
   
    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;
    TNotifyBalloon = class(TComponent)
   
    private
      FTitle: String;
      FText: String;
      NIcon : Integer;
   
    protected
      { Protected declarations }
       FIcon:  TNotifyIcons;
       Data: TNOTIFYICONDATA;
       procedure SetIcon;
   
    public
      { Public declarations }
       ClientHandle : HWND;
       IconHandle : HWND;
       constructor Create(AOwner: Tcomponent); override;
       procedure ShowNotifyBalloon;
       procedure NotifyIcon;
       procedure DeleteIcon;
    published
      { Published declarations }
       property Icon : TNotifyIcons read FIcon write FIcon;
       property Title : String read FTitle write FTitle ;
       property Text : String read FText write FText ;
   
    end;
   
  procedure Register;
   
  implementation
  {*.res}
  constructor TNotifyBalloon.Create(AOwner : TComponent);
  begin
     inherited Create(AOwner);
     FIcon := NIIF_NONE;
  end;
  procedure TNotifyBalloon.NotifyIcon;
  begin
    FillChar(Data,Sizeof(Data),0);
    with Data do
    begin
      cbSize:= Sizeof(Data);
      Wnd:= ClientHandle;
      uID:= 100;
      uFlags:= NIF_ICON;
      hIcon:= IconHandle;
    end;
   
    Shell_NotifyIcon(NIM_ADD,@Data);
   
  end;
   
  procedure TNotifyBalloon.DeleteIcon;
  begin
    FillChar(Data,Sizeof(Data),0);
    with Data do
    begin
      cbSize:= Sizeof(Data);
      Wnd:= ClientHandle;
      uID:= 100;
      hIcon:= IconHandle;
    end;
    Shell_NotifyIcon(NIM_DELETE, @Data);
   
  end;
   
  procedure TNotifyBalloon.SetIcon ;
  begin
     if FIcon = NIIF_NONE then NIcon := $0;
     if FIcon = NIIF_INFO then NIcon := $1;
     if FIcon = NIIF_WARNING then NIcon := $2;
     if FIcon = NIIF_ERROR then NIcon := $3;
     if FIcon = NIIF_USER then NIcon := $4;
   
  end;
   
  procedure TNotifyBalloon.ShowNotifyBalloon;
  begin
    FillChar(Data,Sizeof(Data),0);
    with Data do
      begin
          cbSize:= Sizeof(Data);
          Wnd:= ClientHandle;
          uID:= 100;
          uFlags := NIF_ICON or NIF_INFO;
          hIcon:= Application.Icon.Handle;
          StrLCopy(szInfoTitle,PChar(FTitle),Sizeof(szInfoTitle)-1);
          StrLCopy(szInfo,PChar(FText),Sizeof(szInfo)-1);
          SetIcon;
          dwInfoFlags := NIcon;
      end;
   
    Shell_NotifyIcon(NIM_MODIFY,@data);
   
  end;
  procedure Register;
  begin
    RegisterComponents('Win32', [TNotifyBalloon]);
  end;
   
   
  end.
   
   
  //---------------------------------------------------------
   
  //Instalar el componente.
   
  //Un ejemplo de llamada
  

procedure TForm1.FormCreate(Sender: TObject);
begin

  with NotifyBalloon do
    begin
      IconHandle := Application.Icon.Handle;
      ClientHandle := Handle;
      NotifyIcon;
    end;

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin

 NotifyBalloon.DeleteIcon;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin

 with NotifyBalloon do
  begin
    Icon := NIIF_INFO;
    Title := 'Sugerencia';
    Text := 'Visite http://www.clubdelphi.com para que aprenda el arte de la programación en Delphi.' + #13 +
    'Exponga dudas y sugerencias a todos los foreros del sitio.';
    ShowNotifyBalloon;
  end;

end;


//Si tiene algo que se pueda mejorar díganselo a Roman o a Seoane
Responder Con Cita