Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Minimize to tray

Status
Not open for further replies.
Hi Yizhar,

If you'd go to then you can
download an component for it, and make it visible when
the Application's OnMinimize event fires, and invisible
when the OnRestore event fires. It's quite easy actually.

I hope this helps,

BobbaFet
Everyone has a right to my opinion.
E-mail me at cwcon@programmer.net
 
Some time ago I made a program for checking if a service was running on the computer.

Basicaly what you do is starting a loop with a timer, and changing the icon of the application.

I first made a Resource file with two Icons, named red and green. You can do this with the Image Editor (IMON.RES)

a)I made a form with a TPopupMenu and a TTimer.
b)I modified the WndProc procedure
c)I declared 2 global variables
TNotifyIconData found in the ShellAPI unit, and an integer related to the icons in the resource file.

Richt clicking on the icon in the tray will launch show the PopupMenu
Clicking on details will launch the applications main form
important: declare the ShellAPI unit, otherwise it will not run !!



unit tray1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Menus, ShellAPI;

type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
Details1: TMenuItem;
About1: TMenuItem;
Switch1: TMenuItem;
Exit1: TMenuItem;
Timer1: TTimer;

procedure FormCreate(Sender: TObject);
procedure Details1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TcloseAction);
procedure Timer1Timer(Sender: TObject);
procedure Switch1Click(Sender: TObject);

private
{ Private declarations }
procedure WndProc(var Msg : TMessage); override;
public
{ Public declarations }
IconData: TNotifyIconData;
IconCount: integer;
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
{$R IMON.RES}

procedure TForm1.WndProc(var Msg : TMessage);
var p : Tpoint;
begin
case msg.Msg of
WM_USER + 1: case Msg.LParam of
WM_RBUTTONDOWN:
begin //Right Mouse Button
GetCursorPos(p);
PopupMenu1.Popup(p.x,p.y);
end;
end;
end;
inherited;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
borderIcons := [biSystemMenu];
IconCount := 0; //show the first icon
IconData.cbSize := sizeof(IconData);
Icondata.Wnd := handle;
IconData.uID := 100;
Icondata.uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
IconData.uCallbackMessage := WM_User + 1;
Icondata.hIcon := Application.Icon.Handle;
StrPCopy(Icondata.szTip, Application.Title);
Shell_NotifyIcon(NIM_ADD,@IconData);
Timer1.interval := 1000; //setting the timer
Timer1.Enabled := true;
end;


// show main form
procedure TForm1.Details1Click(Sender: TObject);
begin
Form1.Show;
ShowWindow(Application.Handle, SW_Hide);
end;

procedure TForm1.Exit1Click(Sender: TObject);
begin
Shell_NotifyIcon(NIM_Delete, @IconData);
Application.ProcessMessages;
Application.Terminate;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:= caNone;
Form1.Hide;
end;

//implement here some monitoring stuff
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Case (IconCount) of
0: begin
Icon.handle := LoadIcon(HInstance,'GREEN');
Application.Title := ' Dialogic Running';
end;
1: begin
Icon.handle:= LoadIcon(HInstance,'RED');
Application.Title := ' Dialogic Stopped';
end;
end;
IconData.hIcon:= Icon.handle;
StrPCopy(IconData.szTip,Application.Title);
Shell_NotifyIcon(NIM_MODIFY,@IconData);
end;

//manual switch of icon, can also used to shut another progam down
procedure TForm1.Switch1Click(Sender: TObject);
begin
if IconCount = 0 then IconCount := 1
else IconCount := 0;
end;



//This starts the program
begin
ShowWindow(Application.Handle,SW_Hide);
end.

Regards S. van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top