Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

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

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
scheiko
Asked:
scheiko
1 Solution
 
JimBob091197Commented:
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
 
BoRiSCommented:
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
 
BoRiSCommented:
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
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.

 
BoRiSCommented:
JimBob sorry didn't see your comment when I read the message...

Later

BoRiS
0
 
interCommented:
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
 
scheikoAuthor Commented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now