Помещаем иконку в Tray в Delphi

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ShellApi; //!!
 
const
  WM_NOTIFYTRAYICON = WM_USER + 1;
 
type
  TForm1 = class(TForm)
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure WMTRAYICONNOTIFY(var Msg: TMessage);
    message WM_NOTIFYTRAYICON;
 public
   { Public declarations }
 end;
 
var
  Form1: TForm1;
  tray: TNotifyIconData;
  TrayIcon: TIcon;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.WMTRAYICONNOTIFY(var Msg: TMessage);
begin
  {обрабатываем события на иконке в трее}
  case Msg.LParam of
    WM_LBUTTONDOWN: Form1.Visible:=true;
    WM_LBUTTONDBLCLK: {ваш код}
    WM_LBUTTONUP: {ваш код}
    WM_RBUTTONDOWN: {ваш код}
    WM_RBUTTONDBLCLK: {ваш код}
    WM_RBUTTONUP: {ваш код}
    WM_MOUSEMOVE: {ваш код}
end;
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  try
    with tray do
    begin
      cbSize := SizeOf(TNotifyIconData);
      Wnd := Form1.Handle;
      uID := 1;
    end;
    Shell_NotifyIcon(NIM_DELETE, Addr(tray));
  finally
    Application.Terminate;
  end;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  TrayIcon := Application.Icon;
  with tray do
  begin
    cbSize := SizeOf(TNotifyIconData);
    Wnd := Form1.Handle;
    uID := 1;
    uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
    uCallBackMessage := WM_NOTIFYTRAYICON;
    hIcon := TrayIcon.Handle;
    szTip := ('Это мое приложение в трее');
  end;
  Shell_NotifyIcon(NIM_ADD, Addr(tray));
end;
 
procedure TForm1.GoToTrayButtonClick(Sender: TObject);
begin
  //сворачиваемся в Трей
  Form1.Visible:=false;
end;
Kwork.ru - услуги фрилансеров от 500 руб.
1 Звезда2 Звезды3 Звезды4 Звезды5 Звезд (14 оценок, среднее: 5,00 из 5)
Загрузка...
Добавить комментарий