Richard Coffre
asked on
Delphi 6 and Tray Icon
I know that in previous versions, you can use something called Tray Icon, how can I use this feature in Delphi 6 ?
An example ?
Thanks in advance
An example ?
Thanks in advance
ASKER
I tested it but when I run it, I don't see the specific button to iconify it as a tray icon. Normally it's a button at the left of the 3 usual : Minimize, Restore, Close.
????
????
That would have been an extra feature of the tray component you were using. Its not something that is standard which every tray application has, although it's nice.
I guess I misunderstood you. (seems to be the game played here these days...) I thought you wanted a tray Icon for your application. The tray Icon is the area where the digital clock is located on the Taskbar. If you've assigned an Icon to your form you'll see that Icon next to the clock on the taskbar when the application starts.
This button next to the MinMax/Position/Close buttons on the form (Iconify) sounds more like a Unix feature. I can't ever recall seeing this type of button on a windows application, but I've been wrong before.
There is most likely a way of doing this. I admitedly don't know how. Maybe one of the other experts will join in and give you your answer. I gave you what you orginally asked for basedon the detail of your question.
;]
GEM
This button next to the MinMax/Position/Close buttons on the form (Iconify) sounds more like a Unix feature. I can't ever recall seeing this type of button on a windows application, but I've been wrong before.
There is most likely a way of doing this. I admitedly don't know how. Maybe one of the other experts will join in and give you your answer. I gave you what you orginally asked for basedon the detail of your question.
;]
GEM
ASKER
You can have a look to LeechFTP to see an example of what I described below.
I will retry your example tomorrow.
;-))
Richard
I will retry your example tomorrow.
;-))
Richard
Hello
Here's a sample for tray icon, It's work fine with Delphi 6(I test it with it), I hope that what are you looking for :)
//==
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,ShellApi;
const
WM_MYTRAYICONCALLBACK = WM_USER + 1000;
type
TForm1 = class(TForm)
PopupMenu1 : TPopupMenu;
Close1 : TMenuItem;
Restore1 : TMenuItem;
procedure Close1Click(Sender: TObject);
procedure Restore1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
MyTrayIcon: TNotifyIconData;
procedure AppMinimize(Sender:TObject );
procedure WMMyTrayIconCallback(var Msg:TMessage);
message WM_MYTRAYICONCALLBACK;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMinimize := AppMinimize;
ShowWindow(Application.Han dle, SW_HIDE);
MyTrayIcon.cbSize := SizeOf(TNotifyIconData);
MyTrayIcon.Wnd := Handle;
MyTrayIcon.uId := 1;
MyTrayIcon.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
MyTrayIcon.uCallBackMessag e := WM_MYTRAYICONCALLBACK;
MyTrayIcon.hIcon := Application.Icon.Handle;
MyTrayIcon.szTip := 'Click on Icon to see the options';
Shell_NotifyIcon(NIM_ADD, @MyTrayIcon);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELET E, @MyTrayIcon);
Application.Terminate;
end;
procedure TForm1.AppMinimize(Sender: TObject);
begin
Application.Minimize;
ShowWindow(Application.Han dle, SW_HIDE);
end;
procedure TForm1.WMMyTrayIconCallbac k(var Msg:TMessage);
var
CursorPos : TPoint;
begin
case Msg.lParam of
WM_LBUTTONDOWN :
begin
GetCursorPos(CursorPos);
PopupMenu1.Popup(CursorPos .X,CursorP os.Y);
end;
end;
end;
procedure TForm1.Close1Click(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELET E, @MyTrayIcon);
Application.Terminate;
end;
procedure TForm1.Restore1Click(Sende r: TObject);
begin
Application.Restore;
ShowWindow(Application.Han dle, SW_Show);
end;
end.
Best regards
Mohammed Nasman
Here's a sample for tray icon, It's work fine with Delphi 6(I test it with it), I hope that what are you looking for :)
//==
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,ShellApi;
const
WM_MYTRAYICONCALLBACK = WM_USER + 1000;
type
TForm1 = class(TForm)
PopupMenu1 : TPopupMenu;
Close1 : TMenuItem;
Restore1 : TMenuItem;
procedure Close1Click(Sender: TObject);
procedure Restore1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
MyTrayIcon: TNotifyIconData;
procedure AppMinimize(Sender:TObject
procedure WMMyTrayIconCallback(var Msg:TMessage);
message WM_MYTRAYICONCALLBACK;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMinimize := AppMinimize;
ShowWindow(Application.Han
MyTrayIcon.cbSize := SizeOf(TNotifyIconData);
MyTrayIcon.Wnd := Handle;
MyTrayIcon.uId := 1;
MyTrayIcon.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
MyTrayIcon.uCallBackMessag
MyTrayIcon.hIcon := Application.Icon.Handle;
MyTrayIcon.szTip := 'Click on Icon to see the options';
Shell_NotifyIcon(NIM_ADD, @MyTrayIcon);
end;
procedure TForm1.FormDestroy(Sender:
begin
Shell_NotifyIcon(NIM_DELET
Application.Terminate;
end;
procedure TForm1.AppMinimize(Sender:
begin
Application.Minimize;
ShowWindow(Application.Han
end;
procedure TForm1.WMMyTrayIconCallbac
var
CursorPos : TPoint;
begin
case Msg.lParam of
WM_LBUTTONDOWN :
begin
GetCursorPos(CursorPos);
PopupMenu1.Popup(CursorPos
end;
end;
end;
procedure TForm1.Close1Click(Sender:
begin
Shell_NotifyIcon(NIM_DELET
Application.Terminate;
end;
procedure TForm1.Restore1Click(Sende
begin
Application.Restore;
ShowWindow(Application.Han
end;
end.
Best regards
Mohammed Nasman
hmm...this looks familiar Mohammed. Do you know how to put a 'Iconify' button on the forms' top bar next to the Min/maz - restore (or position) - close buttons?
Yea the real question is "How can I put a 4th button on the right of the caption/title bar?". I know what he's talking about (most programs that have this 4th button use an image of what looks like a period, and performs "minimize to tray") which is where the confusion comes from.
ASKER
I think that the last remark of MannSoft is really good and it is the right question.
So do you have an example because I'm a newbie with VCL ...
Thanks in advance,
Richard
So do you have an example because I'm a newbie with VCL ...
Thanks in advance,
Richard
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If I copy directly the code above it raised some issues because I don't put the control on the form.
Then I found the control for the PopUp Menu but I don't find the one for "Close1 : TMenuItem;", I put a Toolbar but I'm unable to know what I have to do after.
Any ideas ?
Then I found the control for the PopUp Menu but I don't find the one for "Close1 : TMenuItem;", I put a Toolbar but I'm unable to know what I have to do after.
Any ideas ?
before u copy the code to ur form
add popmenu, then add to items to it, first one is restore and the other is close
add popmenu, then add to items to it, first one is restore and the other is close
give me ur email, or send me email at nasman@mogaza.org, and i will send u the project
ASKER
Thanks a lot
Select an Icon for the form
Then use this code:
++++++++++++++cut below the line+++++++++++++++++
unit cshowicon;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI;
type
TForm1 = class(TForm)
procedure FormDestroy(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
pnid : TNotifyIconData;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormDestroy(Sender:
begin
pnid.uFlags := 0;
Shell_NotifyIcon(NIM_DELET
end;
procedure TForm1.FormActivate(Sender
begin
pnid.cbSize := SizeOf(pnid);
pnid.Wnd := Form1.Handle;
pnid.uID := 0;
pnid.uCallbackMessage := WM_MOUSEMOVE;
pnid.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
pnid.hIcon := Form1.Icon.Handle;
pnid.szTip := 'Tips';
Shell_NotifyIcon(NIM_ADD,@
end;
end.
+++++++++++++++cut above the line++++++++++++++++++++