How i can an application in the system tray

Dear Experts
I want to program an application when i run it, an icon apears in the system tray and there wouldn't be any icon in taskbar
Please help me
shaasousaaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LRHGuyCommented:
Check this out:

http://sourceforge.net/projects/tpsystools/

It's free and includes source! There's a trayicon unit!
0
Mohammed NasmanSoftware DeveloperCommented:
System Tray Delphi application - quick and easy
http://delphi.about.com/od/kbwinshell/l/aa121801a.htm

Starting an application as an icon in the system tray
http://www.latiumsoftware.com/en/delphi/00035.php
0
Melih SARICAOwnerCommented:
or with this code..

add shellapi to uses ,


add   mNotIcon      : _NOTIFYICONDATA;  as GLOBAL variable

To add the icon

 mNotIcon.Wnd:=form1.Handle;
 mNotIcon.hIcon:=Application.Icon.Handle;
 mnoticon.szTip:='Port Connector - Click To Open';
 mNotIcon.uFlags:=NIF_ICON+NIF_TIP+NIF_MESSAGE;
 mNotIcon.uCallbackMessage:=mNotMessage;
 Shell_NotifyIcon(NIM_ADD, @mNotIcon);

TO delete the icon
 Shell_NotifyIcon(NIM_Delete, @mNotIcon);

to modify Icon
  modify vaiables in the mnoticon record

then
 Shell_NotifyIcon(NIM_MODIFY, @mNotIcon);

Melih SARICA


0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Ivanov_GCommented:
you can use some component for Tray Icon or the code below (if you want to do it by yourself)

unit Unit1;

interface

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

const
  WM_SYSTRAYCLICK        = WM_USER + 1;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    NotifyIcon : TNotifyIconData;
    procedure InitNotifyIcon;
  protected
    procedure WMSysTrayClick(var Msg : TMessage); message WM_SYSTRAYCLICK;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.InitNotifyIcon;
begin
  // initialize NotifyIcon which will be placed in SysTray.
  with NotifyIcon do
    begin
      cbSize            := SizeOf(NotifyIcon);
      Wnd               := Handle;
      uID               := 1;
      uFlags            := NIF_TIP + NIF_MESSAGE + NIF_ICON;
      uCallbackMessage  := WM_SYSTRAYCLICK;
      hIcon             := Application.Icon.Handle;
      StrPCopy(szTip, Application.Title);
    end;
end;

procedure TForm1.WMSysTrayClick(var Msg: TMessage);
var
  crs_pos                : TPoint;
begin
  // event handler for systray icon click
  case Msg.LParam of
    WM_LBUTTONDBLCLK     : begin
                             // double click with left mouse button
                             Form1.Show;
                           end;
    WM_RBUTTONDOWN       : begin
                             // right button
                             GetCursorPos(crs_pos);
                             //PopupMenu1.Popup(crs_pos.X, crs_pos.Y);
                           end;
    else
      inherited;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // init the systray icon and minimize
  InitNotifyIcon;
  Shell_NotifyIcon(NIM_ADD, Addr(NotifyIcon));
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  // remove the systray icon
  Shell_NotifyIcon(NIM_DELETE, Addr(NotifyIcon));
end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HypoviaxCommented:
0
SaLzCommented:
ok, one easy way of putting your app into the systray, is below.
pur a popupmenu1 on your form.

//put this in your dpr file, this will stop your app from showing up.
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.ShowMainForm:= false; //put this part into th dpr file this will stop the form showing when started up.
  Application.Run;
end.

========
unit main;

interface

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

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    Quit1: TMenuItem;
    procedure Quit1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    procedure TrayIconPopUp(var Msg: TMessage); message WM_USER+1;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  TrayData: TNotifyIconData;
implementation

{$R *.dfm}

function TrayIcon(method:string):string;
begin
if method = 'install' then begin
  with TrayData do begin
    cbSize := SizeOf(TrayData);
    Wnd := Form1.Handle;
    uID := 0;
    uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
    uCallbackMessage := WM_USER+1;
    hIcon := Application.Icon.Handle;
    szTip := 'Piccel';
    Shell_NotifyIcon(NIM_ADD,@TrayData);
  end;
end else if method = 'uninstall' then begin
  Shell_NotifyIcon(NIM_DELETE,@TrayData);
end;
end;

procedure TForm1.TrayIconPopUp(var Msg: TMessage);
var
  p:TPoint;
begin
  if Msg.lParam=WM_LBUTTONDOWN then begin
    form1.Show;
  end else
  if Msg.lParam=WM_RBUTTONDOWN then begin
    SetForegroundWindow(Handle);
    GetCursorPos(p);
    PopupMenu1.Popup(p.x,p.y);
    PostMessage(Handle,WM_NULL,0,0);
  end;
end;

procedure TForm1.Quit1Click(Sender: TObject);
begin
  application.Terminate
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TrayIcon('install');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  TrayIcon('uninstall');
end;

end.
0
SaLzCommented:
object Form1: TForm1
  Left = 192
  Top = 144
  Width = 245
  Height = 158
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object PopupMenu1: TPopupMenu
    Left = 8
    Top = 8
    object Quit1: TMenuItem
      Caption = 'Quit'
      OnClick = Quit1Click
    end
  end
end
0
TiborKiCommented:
Use CoolTrayIcon.

http://www.torry.net/vcl/system/trayicons/trayicon.zip

About(copied from torry):

CoolTrayIcon is a tray icon component with many properties to customize the icon's behaviour and appearance. Features include:

    * Various mouse and click events
    * Popup menu support
    * Methods for hiding and showing the main form
    * Can move to tray when user minimizes the form
    * Icon animation
    * Interactive balloon hints
    * Can convert bitmaps to icons
    * Design preview for easy experimentation
    * The component can be used in a service
    * Restores tray icon on Explorer crash

Includes a descended tray icon component, TextTrayIcon, which allows you to show a tray icon with a text of your choice.

8 demos included (1 exe-demo).
0
TiborKiCommented:
I was good!
0
SaLzCommented:
ye but mine owns all ya! ;-)
0
HypoviaxCommented:
Split between Ivanov_G, Salz and me, as all provided working examples.
0
TiborKiCommented:
Split between Ivanov_G, Salz, Hypoviax and me, as all ( :-) )  provided working examples.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.