Solved

Icon in System Tray

Posted on 1998-10-23
7
325 Views
Last Modified: 2010-04-06
How do I put an application's icon in the system tray and not display anything on the taskbar in Win NT?
0
Comment
Question by:danGynn
[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
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 150 total points
ID: 1344168
Here is how....

const
  wm_IconMessage = wm_User;
TForm1 = class(TForm)
{...}
  public
    procedure IconTray (var Msg: TMessage);
      message wm_IconMessage;
  private
    nid: TNotifyIconData;
  end;
{...}

procedure TMemForm.IconTray (var Msg: TMessage);
var
  Pt: TPoint;
begin
  if Msg.lParam = wm_rbuttondown then
  begin
    GetCursorPos (Pt);
//    SetForegroundWindow (Handle);
    PopupMenu1.Popup (Pt.x, Pt.y);
  end;
  if Msg.lParam = wm_lbuttondblclk then
    Details1Click (self);
end;

procedure TMemForm.FormCreate(Sender: TObject);
begin
  // load the initial icon
  Icon.Handle :=
    LoadIcon (HInstance, 'GREEN');
  // fill the NotifyIcon data structure
  nid.cbSize := sizeof (nid);
  nid.wnd := Handle;
  nid.uID := 1; // icon ID
  nid.uCallBAckMessage := wm_IconMessage;
  nid.hIcon := Icon.Handle;
  nid.szTip := 'Free memory';
  nid.uFlags := nif_Message or
    nif_Icon or nif_Tip;
  Shell_NotifyIcon (NIM_ADD, @nid);
end;
//Destroy the IconTray
procedure TMemForm.FormDestroy(Sender: TObject);
begin
  nid.uFlags := 0;
  Shell_NotifyIcon (NIM_DELETE, @nid);
end;

To modify something like the hint or something you need to do this...

Shell_NotifyIcon (NIM_MODIFY, @nid);

Cheers,
Viktor
0
 

Author Comment

by:danGynn
ID: 1344169
What do I need to include in the USES clause for a TNotifyIconData?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344170
Here is what I've got...

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

Cheers,
Viktor
0
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!

 

Author Comment

by:danGynn
ID: 1344171

Okay, how do I do it so that it only shows up in the icon tray and not on the task bar?  Basically, how do I make it not show up on the task bar?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344172
To hide your app from the taskbar  just add this code in your OnCreate() of the form....
procedure TForm1.WhateverCreate(Sender : TOBject);
begin
  SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end;

Now if you don't want to show your app in the beginning do this .,

First open up the Source to the project....not the unit's source(not the .pas files) open up the .dpr file....

Add this to it,,

Aplication.CreateForm(....);
Application.ShowMainForm := False; //Add only this line..the others are just to show you where to put it....
Application.Run;

Then if you want to show your form in OnClick() of the icon at the system tray just use this code...
Note: I gave you this code above too, but take a look at the place where I commented that this is the only change below...

procedure TMemForm.IconTray (var Msg: TMessage);
   var
     Pt: TPoint;
   begin
     if Msg.lParam = wm_rbuttondown then
     begin
       GetCursorPos (Pt);
   //    SetForegroundWindow (Handle);
       PopupMenu1.Popup (Pt.x, Pt.y);
     end;
     if Msg.lParam = wm_lbuttondblclk then
       Form1.Show;//The only change I made from the example I gave you above.... This shows the form in OnClick() of the icon at the system tray...
end;

If you need more help just ask...

Cheers,
Viktor
0
 

Author Comment

by:danGynn
ID: 1344173
Adjusted points to 150
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1344174
Thanks!

If you need more help just say so =)

Cheers,
Viktor
0

Featured Post

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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 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