Solved

How to move application from taskbar to systray (notification area)

Posted on 1998-03-27
6
361 Views
Last Modified: 2010-04-06
Hi there,

Does anybody have any idea how to move the icon of an active application (on the win95 or winNT taskbar) to the systray area (the notification area next to the clock in the lower right corner of the taskbar). If it's not so difficult as i think then please give an example using a simple form that after starting appears on screen (and on the taskbar) and after clicking minimize removes the application from the taskbar to the systray.

Thanks for your help!

Scheiko
0
Comment
Question by:scheiko
6 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360967
Hi

I have a tray icon component that you just drop on the form.  Mail your e-mail address to me at davekw@iafrica.com, and I will mail you the component with a sample.

Regards,
JB
0
 
LVL 4

Accepted Solution

by:
BoRiS earned 300 total points
ID: 1360968
this will show how to do it in code, i have it as a component if you wish......

add this to your public declaration

  public
    { Public declarations }
  procedure IconCallBackMessage( var Mess : TMessage ); message WM_USER
  + 100;
  end;

then on formCreate add this code ....

var
   Icd : TNotifyIconData;
begin
     with Icd do
     begin
           cbSize := SizeOf( TNotifyIconData );
           Wnd := Form1.Handle;
           uID := 1;
           uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
           uCallbackMessage := WM_USER + 100;
           hIcon := Application.Icon.Handle;
           szTip := 'Cool I got it right Wooooo Weeeee';
     end;
     Shell_NotifyIcon( NIM_ADD, @Icd );
end;

add this to your formClose

var
   Icd : TNotifyIconData;
begin
     with Icd do
     begin
           cbSize := SizeOf( TNotifyIconData );
           Wnd := Form1.Handle;
           uID := 1;
           uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
           uCallbackMessage := WM_USER + 100;
           hIcon := Application.Icon.Handle;
           szTip := 'Cool I got it right Wooooo Weeeee';
// All the above is probably not needed.
     end;
     Shell_NotifyIcon( NIM_DELETE, @Icd );
end;


Then here is the proceure for the IconCallBackMessage.....

procedure TForm1.IconCallBackMessage( var Mess : TMessage );
var
   sEventLog : String;
begin
     case Mess.lParam of
// Do whatever you wish here. For example popup up a menu on a right click.
          WM_LBUTTONDBLCLK  : sEventLog := 'Left Double Click';
          WM_LBUTTONDOWN    : sEventLog := 'Left Down';
          WM_LBUTTONUP      : sEventLog := 'Left Up';
          WM_MBUTTONDBLCLK  : sEventLog := 'M Dbl';
          WM_MBUTTONDOWN    : sEventLog := 'M D';
          WM_MBUTTONUP      : sEventLog := 'M U';
          WM_MOUSEMOVE      : sEventLog :=  'movement';
          WM_MOUSEWHEEL     : sEventLog := 'Wheel';
          WM_RBUTTONDBLCLK  : sEventLog := 'r dbl';
          WM_RBUTTONDOWN    : sEventLog := 'r down';
          WM_RBUTTONUP      : sEventLog := 'r up';
     end;
end;
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1360969
sorry forgot to give you code to hide taskbar icon

add this to hide taskbar icon in the onformCreate

ShowWindow(application.handle, SW_HIDE); //to hide icon


to show the the icon again just swop the SW_HIDE with SW_SHOW

Later

BoRiS
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.

 
LVL 4

Expert Comment

by:BoRiS
ID: 1360970
JimBob sorry didn't see your comment when I read the message...

Later

BoRiS
0
 
LVL 5

Expert Comment

by:inter
ID: 1360971
Hi friends,

The following one does the example you want. Since, the question is answered previously I do not claim any points.

Just cut and past the following code to an empy form

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure WndProc(var Message: TMessage);override;
  public
    { Public declarations }
    procedure UpdateIconData;
    procedure AppMinimize(Sender: TObject);
    procedure AppRestore(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
uses ShellApi;

const
  CM_TRAYICON        = CM_BASE + 64;

var
  IconData : TNotifyIconData;

procedure Tform1.UpdateIconData;
begin
  with IconData do begin
    cbSize := SizeOf(TNotifyIconData);
    Wnd := Handle;
    uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
    hIcon := Application.Icon.Handle;
    szTip := 'this is test tip';
    uCallbackMessage := CM_TRAYICON;
    uID := 0;
  end;
end;

procedure TForm1.AppMinimize(Sender: TObject);
begin
  UpdateIconData;
  Shell_NotifyIcon(NIM_ADD, @IconData);
  //Hide window on task bar
  ShowWindow(Application.Handle, SW_HIDE);
end;

procedure TForm1.AppRestore(Sender: TObject);
begin
  Shell_NotifyIcon(NIM_DELETE, @IconData);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMinimize := AppMinimize;
  Application.OnRestore := AppRestore;
end;

procedure TForm1.WndProc(var Message: TMessage);
begin
  try
    with Message do
      if Msg = CM_TRAYICON then begin
        case Message.lParam of
          WM_LBUTTONDBLCLK,
          WM_LBUTTONUP,
          WM_RBUTTONUP:  begin
                         ShowWindow(Application.Handle, SW_SHOW);
                         Application.Restore;
                         end;
        end;
      end
      else inherited WndProc(Message);
  except
    Application.HandleException(Self);
  end;
end;

end.


Regards,
Igor
0
 

Author Comment

by:scheiko
ID: 1360972
JimBoB:I'll mail you to ask you for the component.

Thanks Guys! I'll try it all until i find the one that suits me best (I think two are the same, you guys've been in class together? :)

Regards,
Scheiko
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

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

18 Experts available now in Live!

Get 1:1 Help Now