Solved

How to put an icon into the tray

Posted on 2000-03-12
11
353 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
 
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
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.

 

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

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 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

16 Experts available now in Live!

Get 1:1 Help Now