?
Solved

Icon in System Tray

Posted on 1998-10-23
7
Medium Priority
?
331 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

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 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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 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