Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to put an icon into the tray

Posted on 2000-03-12
11
356 Views
Last Modified: 2010-04-04
This may be really easy, but I am looking for a way to put an icon into the tray (95/98/NT) when my program is running and not have it appear on the task bar.  Any clues?
0
Comment
Question by:toesable
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2611109
0
 

Author Comment

by:toesable
ID: 2611140
Perhaps I am doing something wrong.  Got to ftp://ftp.cdrom.com/pub but there wasn't anything in delphi_www and the full path of each of these was unavailable.  
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2611161
Thats weird - perhaps the site is down at the moment.

Try this link:

http://www.devgr.com/docs/systray.html

Cheers,

Raymond.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 2611163
You could also check out the mirrors here (http://dsp.href.com/iis/iis.dll?DSP:MIRRORS:221813813) for other download locations.

Cheers,

Raymond.
0
 

Author Comment

by:toesable
ID: 2611280
devgr is for delphi 2, and it doesn't include the code only the dcu.  I'm looking for how to do it.  I will wait a few hours and try to get into the htp you reccomended.
0
 

Author Comment

by:toesable
ID: 2611862
Sorry, I am still unable to access the sites other than the one that has no source and is for delphi 2.  Perhaps I can get another answer.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2613376
Download the Tray Icon Example from the site below. It will give you all the code for doing that + sample application.

http://home.ican.net/~wniddery/freedelphistuff.html 

Cheers,

Raymond.
0
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 2613494
here an example for a animated icon in the tray:

const
  WM_MYTRAYICONCALLBACK = WM_USER + 1000;

type
  TForm1 = class(TForm)
    PopupMenu1 : TPopupMenu;
    Close1     : TMenuItem;
    Restore1   : TMenuItem;
    Timer1     : TTimer;
    procedure Close1Click(Sender: TObject);
    procedure Restore1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    HIcon1, HIcon2 : HICON;
    MyTrayIcon: TNotifyIconData;
    procedure AppMinimize(Sender:TObject);
    procedure WMMyTrayIconCallback(var Msg:TMessage);
                       message WM_MYTRAYICONCALLBACK;
  public
    { Public declarations }
  end;

{...}

procedure TForm1.FormCreate(Sender: TObject);
begin
  { load our icons }
  HIcon1 := LoadIcon(0, IDI_WINLOGO);
  HIcon2 := LoadIcon(0, IDI_HAND);

  { set TApplictaion.OnMinimize to our new event }
  Application.OnMinimize := AppMinimize;

  { start our application minimized to the System Tray }
  Visible := FALSE;
  Application.ShowMainForm := Visible;

  { required to set cbSize to SizeOf our structure }
  MyTrayIcon.cbSize := SizeOf(TNotifyIconData);

  { handle to main window }
  MyTrayIcon.Wnd    := Handle;

  { identifier of our icon }
  MyTrayIcon.uId    := 1;

  { flags showing what we are using in the other members below }
  MyTrayIcon.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;

  { our user defined message }
  MyTrayIcon.uCallBackMessage := WM_MYTRAYICONCALLBACK;

  {  set our icon to the first one loaded above }
  MyTrayIcon.hIcon  := HIcon1;

  { help message of the icon }
  MyTrayIcon.szTip  := 'Lou''s Delphi Tip of the Day [MyTrayIcon]';

  { add our icon to the tray }
  Shell_NotifyIcon(NIM_ADD, @MyTrayIcon);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  { remove our icon from the tray }
  Shell_NotifyIcon(NIM_DELETE, @MyTrayIcon);
end;

procedure TForm1.AppMinimize(Sender:TObject);
begin
  { hide our application }
  Visible := FALSE;
  Application.ShowMainForm := Visible;
end;

procedure TForm1.WMMyTrayIconCallback(var Msg:TMessage);
var
  CursorPos : TPoint;
begin
  case Msg.lParam of
    WM_LBUTTONDOWN :
      begin
        { get mouse cursor position }
        GetCursorPos(CursorPos);
        { popup our TPopupMenu }
        PopupMenu1.Popup(CursorPos.X,CursorPos.Y);
      end;
  end;
end;

procedure TForm1.Close1Click(Sender: TObject);
begin
  { close our application }
  Close;
end;

procedure TForm1.Restore1Click(Sender: TObject);
begin
  { restore our application, or minimize if already
    in a restore mode }
  Visible := TRUE;
  Application.ShowMainForm := Visible;
  SetForegroundWindow(Application.Handle);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  { change our icon to the opposite one loaded }
  if MyTrayIcon.hIcon = HIcon1 then
    MyTrayIcon.hIcon := HIcon2
  else
    MyTrayIcon.hIcon := HIcon1;

  { tell the SystemTray to modify our changes }
  Shell_NotifyIcon(NIM_MODIFY, @MyTrayIcon);
end;
0
 
LVL 2

Expert Comment

by:Tussin
ID: 2615367
I think you know how to add icon to the tray (from Raymond's suggestion)

All you want know now is "how we can hide a program from TaskBar?", right?

This is a command to hide program from Taskbar.

  ShowWindow(Application.Handle,SW_HIDE);

and this is a command to show them again
  ShowWindow(Application.Handle,SW_SHOW);


0
 
LVL 17

Expert Comment

by:inthe
ID: 2615891
Tussin,
because you dont really know what the questioner thinks you should put proposed answer as comment.it is more polite.
0
 

Author Comment

by:toesable
ID: 2617760
Thanks inthe, That's the answer I was looking for.

toe
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 91
Working this component WebCopy with proxy, help 3 92
Microsoft Access 97 and Delphi XE2 9 53
DBCtrlGrid, Delphi, Scroll 7 26
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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