[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Icon in System Tray

Posted on 1998-10-23
7
Medium Priority
?
334 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 600 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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