{###############################################################################}
{#     COMPONENTS + TUTORIALS + SAMPLES + PROGRAMS + FORMS + TIPS + TRICKS     #}
{###############################################################################}
{#
{#     Name.........: HellSystemTray
{#     Unit.........: Unit1.pas
{#     Released.....: 29-12-2008 15:09:59                               
{#     Author.......: Nullified
{#     Website......: http://www.delphi7.nl
{#     About........: Example of a system tray program
{#
{###############################################################################}
{#   RATE MY SITE IF YOU THINK I DESERVE IT I WOULD APPRECIATE IT THANKS!!     #}
{###############################################################################}
unit tray;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus;

const
  WM_ShellIcon = WM_USER + 1;

type
  TForm1 = class(TForm)
    pm1: TPopupMenu;
    viewApp: TMenuItem;
    exitApp: TMenuItem;
    minimizeApp: TMenuItem;
    procedure FormActivate(Sender: TObject);
    procedure exitAppClick(Sender: TObject);
    procedure viewAppClick(Sender: TObject);
    procedure minimizeAppClick(Sender: TObject);
  private
    { Private declarations }
    procedure ShellIcon( var Msg : TMessage ); message WM_ShellIcon;
    procedure OnMinimize( var Msg : TWMSysCommand ); message WM_SYSCOMMAND;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.ShellIcon(var Msg: TMessage);
var
  Point : TPoint;
begin
  case Msg.LParam of
    WM_LBUTTONDBLCLK : begin
                         Show;
                         SetForegroundWindow( Handle );
                       end;
    WM_RBUTTONUP     : begin
                         SetForegroundWindow( Handle );
                         GetCursorPos( Point );
                         pm1.Popup( Point.x, Point.y );
                         PostMessage( Handle, WM_USER, 0, 0 );
                       end;
  end;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  ShowWindow(Application.Handle, SW_HIDE);
end;

procedure TForm1.exitAppClick(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.OnMinimize(var Msg: TWMSysCommand);
begin
  if( Msg.CmdType = SC_MINIMIZE ) or
    ( Msg.CmdType = SC_CLOSE    ) then
    Hide
  else
    inherited;
end;

procedure TForm1.viewAppClick(Sender: TObject);
begin
  Show;
  SetForegroundWindow( Handle );
end;

procedure TForm1.minimizeAppClick(Sender: TObject);
begin
  Hide;
end;

end.
