Lonewolf Online

The website of an amateur photographer, astronomer and petrolhead.

Minimise to System Tray

Program icon will be displayed in the System Tray when the form is minimised.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ShellApi;

const
  WM_NOTIFYICON  = WM_USER+333;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    tnid: TNotifyIconData;
    HMainIcon: HICON;
    procedure CMClickIcon(var msg: TMessage); message WM_NOTIFYICON;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.CMClickIcon(var msg: TMessage);
begin
  case msg.lparam of
    WM_LBUTTONDBLCLK : Show;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  HMainIcon                := LoadIcon(MainInstance, 'MAINICON');

  Shell_NotifyIcon(NIM_DELETE, @tnid);

  tnid.cbSize              := sizeof(TNotifyIconData);
  tnid.Wnd                 := handle;
  tnid.uID                 := 123;
  tnid.uFlags              := NIF_MESSAGE or NIF_ICON or NIF_TIP;
  tnid.uCallbackMessage    := WM_NOTIFYICON;
  tnid.hIcon               := HMainIcon;
  tnid.szTip               := 'POP3 Server';

  Shell_NotifyIcon(NIM_ADD, @tnid);
end;

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

//If desired, you can tell Delphi not to show the mainform by adding to the
//'Project source' the line
//  Application.ShowMainForm := False;

//(Credits for this go to Peter Remeijer)

end.

Results:

Program icon will be displayed in the System Tray when the form closes.

Explanation:

Notice that this will prevent the form from being closed. The Hide procedure will remove the window, but the form is still present and now accessible through the icon in the system tray.

Notes:

Although this code will allow you to place your applications main icon in the system tray and not in the start bar, there are several very good components available to do this for you. They also encapsulate many associated routines. See the VCL listings on Delphi32.com for tray icons.

 

Share/Save/Bookmark

 

What Others Are Saying

There are no comments for this item yet.

 

Have Your Say

 

 

 

 

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment. The authors reserve the right not to publish any comments that they believe are hateful, racist, demeaning or otherwise inappropriate.

  • Random Photographs
    • Driftworks Demo
    • Duck
    • Black Cats Helicopter Display Team
    • Boundry Ditch
    • Coxs Cave
    • Unknown Cacti
    • RAF C18 Globemaster Taxi
    • Marine Parachute Jump
    • Honda Nsx on Track
    • Montecatini Alto

  • Recent Additions
  • Search




  • Page copy protected against web site content infringement by Copyscape
This page was last updated on Monday, July 28th, 2008.
Unless otherwise stated, all photographs and content Copyright © 2000 - 2008 Tim Trott, All Rights Reserved. No graphics, photographs or content may be used without written permission.
Website Design and Graphics Copyright © 2005-2007 Tim Trott. home :: sitemap :: disclaimer:: contact