问题来源:
http://www.cnblogs.com/del/archive/2009/06/05/1496857.html#1549294
TTrayIcon 的主要属性:
TrayIcon.Icon
指定托盘图标, 有几种用法:
1、设计时选择;
2、把一个 TIcon 对象给它;
3、使用当前程序图标: TrayIcon1.Icon := Application.Icon;
4、TrayIcon1.SetDefaultIcon; 这也是使用当前程序图标.
TrayIcon.Icons 与
TrayIcon1.IconIndex
TrayIcon.Icons 对应一个 TImageList, 用 TrayIcon.IconIndex 来指定使用 TImageList 中的第一个图标.
这结合 TrayIcon 的其他功能做出图标动画都没有问题.
TrayIcon.PopupMenu
TrayIcon.PopupMenu 对应一个 TPopupMenu, 托盘图标一般少不了右键菜单.
TrayIcon.Visible
隐藏或显示系统托盘的图标; 虽简单、但关键, 因默认是 False.
TrayIcon.Hint
随鼠标指针的提示文本, 这是老式的, 下面有新型的.
TrayIcon.BalloonHint、BalloonTitle、BalloonFlags、BalloonTimeout
这都是新型的 Hint 相关的.
TrayIcon.BalloonHint: Hint 文本
TrayIcon.BalloonTitle: Hint 标题
TrayIcon.BalloonFlags: Hint 图标样式
TrayIcon.BalloonTimeout: Hint 停留时间
需要用 TrayIcon 的 ShowBalloonHint 方法启动显示
TrayIcon.Animate 与
TrayIcon1.AnimateInterval
TrayIcon 的新 Hint(BalloonHint)可设定动画.
TrayIcon.Animate: 这决定是否启用动画
TrayIcon1.AnimateInterval: 动画间隔时间
TTrayIcon 的主要事件:
OnAnimate: 写动画代码的事件
OnBalloonClick: 点击 BalloonHint 时...
OnClick: 单击图标时...
OnDblClick
OnMouseDown
OnMouseMove
OnMouseUp
TTrayIcon 还有两个方法, 前面都已提到了:
TTrayIcon.SetDefaultIcon;
TTrayIcon.ShowBalloonHint;
posted @
2009-06-05 18:09 万一 阅读(713) |
评论 (13) |
编辑
问题来源:
http://www.cnblogs.com/del/archive/2009/05/15/1458017.html#1549351
代码文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, AppEvnts;
type
TForm1 = class(TForm)
TrayIcon1: TTrayIcon;
Button1: TButton;
procedure TrayIcon1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{关闭}
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.Terminate;
end;
{点击关闭按钮时让窗体最小化到系统托盘}
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Tag := Ord(WindowState);
WindowState := wsMinimized;
TrayIcon1.SetDefaultIcon;
TrayIcon1.Visible := True;
Hide;
CanClose := False;
end;
{点击系统托盘中的图标恢复窗口}
procedure TForm1.TrayIcon1Click(Sender: TObject);
begin
TrayIcon1.Visible := False;
Show;
WindowState := TWindowState(tag);
SetForegroundWindow(Handle);
end;
end.
窗体文件:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 206
ClientWidth = 339
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCloseQuery = FormCloseQuery
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 232
Top = 40
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object TrayIcon1: TTrayIcon
OnClick = TrayIcon1Click
Left = 160
Top = 104
end
end
posted @
2009-06-05 17:27 万一 阅读(562) |
评论 (5) |
编辑
代码文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
IMyInterface1 = interface
function Func(a,b: Integer): Integer;
end;
TAdd = class(TInterfacedObject, IMyInterface1)
public
function Func(a: Integer; b: Integer): Integer;
destructor Destroy; override;
end;
TMul = class(TInterfacedObject, IMyInterface1)
public
function Func(a: Integer; b: Integer): Integer;
destructor Destroy; override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TAdd }
destructor TAdd.Destroy;
begin
ShowMessage('TAdd.Destroy');
inherited;
end;
function TAdd.Func(a, b: Integer): Integer;
begin
Result := a + b;
end;
{ TMul }
destructor TMul.Destroy;
begin
ShowMessage('TMul.Destroy');
inherited;
end;
function TMul.Func(a, b: Integer): Integer;
begin
Result := a * b;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
I: IMyInterface1;
begin
I := TAdd.Create;
ShowMessage(IntToStr(I.Func(9, 9))); {18}
I := TMul.Create; {I 在指向新的目标前会先释放前面所属的类}
ShowMessage(IntToStr(I.Func(9, 9))); {81}
end;
end.
posted @
2009-06-05 13:27 万一 阅读(629) |
评论 (3) |
编辑
问题来源:
http://www.cnblogs.com/del/archive/2008/01/17/1043226.html#1548952
使用 Delphi 提供的 TTrayIcon 类, 两三行程序甚至不写程序(设计时选择几下)即可实现.
设计时的准备工作:
1、添加 TTrayIcon、TPopupMenu 控件, TPopupMenu 用于托盘的右键菜单.
2、随意给 TPopupMenu 添加些菜单项.
代码文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls;
type
TForm1 = class(TForm)
TrayIcon1: TTrayIcon;
PopupMenu1: TPopupMenu;
aaa1: TMenuItem;
bbb1: TMenuItem;
ccc1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure TrayIcon1DblClick(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
{指定图标, 这里是用程序相同的图标; 也可在设计时选择, 还可以指定一个图标组, 再用 IconIndex 切换}
TrayIcon1.Icon := Application.Icon;
{指定右键菜单}
TrayIcon1.PopupMenu := PopupMenu1;
{使之可见}
TrayIcon1.Visible := True;
end;
{给图标添加到双击事件}
procedure TForm1.TrayIcon1DblClick(Sender: TObject);
begin
ShowMessage('OnDblClick');
end;
end.
窗体文件:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 206
ClientWidth = 339
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object TrayIcon1: TTrayIcon
OnDblClick = TrayIcon1DblClick
Left = 152
Top = 88
end
object PopupMenu1: TPopupMenu
Left = 216
Top = 88
object aaa1: TMenuItem
Caption = 'aaa'
end
object bbb1: TMenuItem
Caption = 'bbb'
end
object ccc1: TMenuItem
Caption = 'ccc'
end
end
end
posted @
2009-06-05 12:15 万一 阅读(581) |
评论 (4) |
编辑