Solved

How to put an icon into the tray

Posted on 2000-03-12
11
351 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

22 Experts available now in Live!

Get 1:1 Help Now