Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to put an icon into the tray

Posted on 2000-03-12
11
Medium Priority
?
362 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
[X]
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
  • 4
  • 4
  • 2
  • +1
11 Comments
 

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

704 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