1. Home
  2. Computing & Technology
  3. Delphi Programming



{
Article: 
System Tray Delphi application - quick and easy

http://delphi.about.com/library/weekly/aa121801a.htm

Placing Delphi applications in the System Tray
in easy steps. The perfect place form programs
that are left running for long periods of time
with no user interaction.
}

UNIT1.PAS

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, shellapi, AppEvnts; const WM_ICONTRAY = WM_USER + 1; type TMainForm = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private TrayIconData: TNotifyIconData; { Private declarations } public procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY; { Public declarations } end; var MainForm: TMainForm; implementation {$R *.dfm} procedure TMainForm.TrayMessage(var Msg: TMessage); begin case Msg.lParam of WM_LBUTTONDOWN: begin ShowMessage('Left button clicked - let''s SHOW the Form!'); MainForm.Show; end; WM_RBUTTONDOWN: begin ShowMessage('Right button clicked - let''s HIDE the Form!'); MainForm.Hide; end; end; end; 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; end.

Project1.PAS

program Project1; uses Forms, Unit1 in 'Unit1.pas' {MainForm}; {$R *.res} begin Application.Initialize; Application.ShowMainForm := False; Application.CreateForm(TMainForm, MainForm); Application.Run; end. { ******************************************** Zarko Gajic About.com Guide to Delphi Programming http://delphi.about.com email: delphi.guide@about.com free newsletter: http://delphi.about.com/library/blnewsletter.htm forum: http://forums.about.com/ab-delphi/start/ ******************************************** }
Explore Delphi Programming
About.com Special Features

Reader's Choice Award Winners

What are the best instant messengers, apps, editors and more? You told us, for our 2010 technology awards program. More >

iPad Central

Is Apple's new tablet computer impractical, a must-have -- or both? We'll help you figure it out. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2010 About.com, a part of The New York Times Company.

All rights reserved.