Solved

Icon in System Tray

Posted on 1998-10-23
7
308 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
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 150 total points
Comment Utility
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
Comment Utility
What do I need to include in the USES clause for a TNotifyIconData?
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Here is what I've got...

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

Cheers,
Viktor
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:danGynn
Comment Utility

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
Comment Utility
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
Comment Utility
Adjusted points to 150
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Thanks!

If you need more help just say so =)

Cheers,
Viktor
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now