Board index » delphi » System tray

System tray

How do I get my program to run in the system tray

Anthony

 

Re:System tray


Quote
Anthony wrote:
>How do I get my program to run in the system tray

Use one of the zillions of free components offered at DSP, Torry, or
elsewhere (e.g. TTrayIcon [tray11.zip])
Regards,
Udo
--
Please reply to newsgroup. Unrequested mails will be ignored.

Re:System tray


Anthony <mcla...@softhome.net> skrev i en
nyhedsmeddelelse:964387947.226...@nznews00.chello.co.nz...

Quote
> How do I get my program to run in the system tray

The easiest way to do it, is by getting a component to do it for you. One
such component can be found in "ZieglerCollection one", that can be found on
our homepage at http://www.zieglersoft.dk or http://www.zieglersoft.com
--

Warmest Regards from Claus Ziegler,

ZieglerSoft             Email: cl...@zieglersoft.dk
Rughaven 25,2           WWW: http://www.zieglersoft.dk
DK-9000 Aalborg           Phone: (+45) 9811 3772
Denmark                            ICQ: 19316950

Re:System tray


Try this one. It works perfect.

Koen
www.win4free.com

Question and Answer Database

FAQ2911D.txt   Creating a Win95 Shell icon application.
Category   :Windows API
Platform    :All
Product    :All 32 bit

Question:
How do I create a Delphi/C++ Builder application that runs in the
system tray?

Answer:
This is done via the ShellAPI function Shell_NotifyIcon(). The
following example shows how to create an application that uses this
function. The example application shows a different icon in the
system tray every second and shows the time in the title. The
application responds to a right click of the mouse by showing a menu
allowing the user to display a form or quit the application. Attempts
to close the form result in the form hiding, but the tray application
continues to run. Note that no task bar icon is shown for the form. To
compile the application, you will need to create a form with a
TPopupMenu and a TTimer component. You will also need to make
modifications to the main project source file (TrayIt.dpr).

Example:

{TrayIt.dpr}

program TrayIt;

uses
  Windows,
  Forms,
  TrayIt1 in 'TrayIt1.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.ShowMainForm := False;
  Application.CreateForm(TForm1, Form1);
  ShowWindow(Application.Handle, SW_HIDE);
  Application.Run;
end.

{TrayIt1.pas}

unit TrayIt1;

interface

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

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    Open1: TMenuItem;
    Exit1: TMenuItem;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Open1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    procedure WndProc(var Msg : TMessage); override;
  public
    { Public declarations }
    IconData : TNotifyIconData;
    IconCount : integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WndProc(var Msg : TMessage);
var
  p : TPoint;
begin
  case Msg.Msg of
    WM_USER + 1:
    case Msg.lParam of
      WM_RBUTTONDOWN: begin
         GetCursorPos(p);
         PopupMenu1.Popup(p.x, p.y);
      end
    end;
  end;
  inherited;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  BorderIcons := [biSystemMenu];
  IconCount := 0;
  IconData.cbSize := sizeof(IconData);
  IconData.Wnd := Handle;
  IconData.uID := 100;
  IconData.uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
  IconData.uCallbackMessage := WM_USER + 1;
  IconData.hIcon := Application.Icon.Handle;
  StrPCopy(IconData.szTip, Application.Title);
  Shell_NotifyIcon(NIM_ADD, @IconData);
  Timer1.Interval := 1000;
  Timer1.Enabled := true;
end;

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

procedure TForm1.Exit1Click(Sender: TObject);
begin
  Shell_NotifyIcon(NIM_DELETE, @IconData);
  Application.ProcessMessages;
  Application.Terminate;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caNone;
  Form1.Hide;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  case(IconCount) of
    0 : IconData.hIcon := LoadIcon(0, IDI_APPLICATION);
    1 : IconData.hIcon := LoadIcon(0, IDI_ASTERISK);
    2 : IconData.hIcon := LoadIcon(0, IDI_EXCLAMATION);
    3 : IconData.hIcon := LoadIcon(0, IDI_HAND);
    4 : IconData.hIcon := LoadIcon(0, IDI_QUESTION);
    5 : IconData.hIcon := Application.Icon.Handle;
  end;
  inc(IconCount);
  if IconCount > 5 then
    IconCount := 0;
  Application.Title := TimeToStr(Now);
  StrPCopy(IconData.szTip, Application.Title);
  Shell_NotifyIcon(NIM_MODIFY, @IconData);
end;

begin
  ShowWindow(Application.Handle, SW_HIDE);
end.

Quote
"Udo Nesshoever" <newsgroup.re...@gmx.net> wrote in message

news:vfrnns47ker1du07g2d98q4i1s806d55jm@4ax.com...
Quote
> Anthony wrote:

> >How do I get my program to run in the system tray

> Use one of the zillions of free components offered at DSP, Torry, or
> elsewhere (e.g. TTrayIcon [tray11.zip])
> Regards,
> Udo
> --
> Please reply to newsgroup. Unrequested mails will be ignored.

Other Threads