[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

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
0
shaasousaa
Asked:
shaasousaa
  • 3
  • 3
  • 2
  • +4
4 Solutions
 
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 SARICACommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now