1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
   | unit Main;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ShellApi ;
 
  Const
   WM_ICONTRAY = WM_USER + 1  ;
 
type
  TMainForm = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
 
  private
    { Déclarations privées }
    TrayIconData: TNotifyIconData;
  public
    { Déclarations publiques }
    procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY;  end;
 
var
  MainForm: TMainForm;
 
implementation
 
{$R *.dfm}
 
{ ============================================================== }
procedure TMainForm.FormCreate(Sender: TObject);
begin
with TrayIconData do
  begin
    cbSize := SizeOf(TrayIconData);
    Wnd := Handle;
    uID := 0;
    uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
    uCallbackMessage := WM_ICONTRAY;
    hIcon := Application.Icon.Handle;
    StrPCopy(szTip, Application.Title);
  end;
 
  Shell_NotifyIcon(NIM_ADD, @TrayIconData);
end;
{ ============================================================== }
procedure TMainForm.FormDestroy(Sender: TObject);
begin
  Shell_NotifyIcon(NIM_DELETE, @TrayIconData);
end;
{ ============================================================== }
procedure TMainForm.TrayMessage(var Msg: TMessage);
begin
  case Msg.lParam of
    WM_LBUTTONDOWN:
    begin
      ShowMessage('Afficher la fenêtre principale');
      MainForm.Show;
    end;
    WM_RBUTTONDOWN:
    begin
      ShowMessage('Cacher la fençetre principale');
      MainForm.Hide;
    end;
  end;
end;
{ ============================================================== }
 
end. | 
Partager