Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Writing a trayIcon application

Posted on 1999-09-01
4
Medium Priority
?
148 Views
Last Modified: 2010-04-04
Hi.........
What do i need to do in order to get my application into the tray icon insted of the task bar ??
0
Comment
Question by:Itzik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 7

Accepted Solution

by:
RBertora earned 200 total points
ID: 1954890
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1955046
or post ur email & i'll send ya a component.

BlackDeath.
0
 

Expert Comment

by:KoenHoebeek
ID: 3774312
Try this :

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.


0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question