Solved

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

Posted on 1998-03-27
6
363 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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