[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Changing icon in tray

Posted on 2001-09-12
4
Medium Priority
?
292 Views
Last Modified: 2010-04-06
Can someone make me a short demo of a plain form with one button that hides the form to the tray. That part is what I already can do. What I need more is that I want to change the icon on a timer. Let's say I want the icon change every second to a new one. How do I enclude the icons and how do I make the program change the icon while hidden in the tray.

Marcel (Holland)
0
Comment
Question by:mpoots
[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 Comments
 
LVL 7

Expert Comment

by:Rob Siddell
ID: 6477531
listening..

Rob
0
 
LVL 4

Expert Comment

by:DMN
ID: 6477629
Really you can use 3rd party component to do it. I wrote suach component som etime ago. If you wish I'll post it tomorrow.
0
 
LVL 17

Accepted Solution

by:
inthe earned 600 total points
ID: 6477747
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;


you can put the icons in your res file and call them using
LoadIcon(Hinstance, IconName);


or you can always go to torrys and get a trayicon comp that will do it:
http://www.torry.net/trayicons.htm

0
 
LVL 1

Author Comment

by:mpoots
ID: 6478638
Perfect! Just what I needed..

Marcel (Holland)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
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…
Suggested Courses

656 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