Solved

Icon in System Tray

Posted on 1998-10-23
7
313 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 95
Create Database on Android via Delphi dbExpress 3 80
Print Graphic and Text to Epson TM-T88v 12 182
LAN or WAN ? 11 82
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

13 Experts available now in Live!

Get 1:1 Help Now