1
142857
Unregistered / Unconfirmed
GUEST, unregistred user!
从vclxx.org下载TrayIcon控件使用,控件非常好用,但是我想达到Windows网络连接状态
的效果,即当程序有任务执行时,可以从托盘图标Hint动态显示结果,如网络连接的传送包数。
但是当鼠标停留在托盘时,这是图标的Hint并不发生变化。
请问:
1。如何达到鼠标悬停的Hint可以动态变化呢?对于TNotifyData结构填充结构需要填充
什么内容就可以达到效果呢?
以下是测试程序unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellAPI, Menus, ComCtrls, ExtCtrls, TrayIcon, ImgList;
type
TMainForm = class(TForm)
pmiPopup: TPopupMenu;
pgclPageCtl: TPageControl;
TabSheet1: TTabSheet;
btnClose: TButton;
btnTerm: TButton;
Terminate1: TMenuItem;
Label1: TLabel;
N1: TMenuItem;
Propeties1: TMenuItem;
Timer1: TTimer;
TrayNotifyIcon1: TGrisTrayIcon;
ImageList2: TImageList;
procedure NotifyIcon1Click(Sender: TObject);
procedure NotifyIcon1DblClick(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure btnTermClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
Rever:Boolean;
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.NotifyIcon1Click(Sender: TObject);
begin
ShowMessage('Single click');
end;
procedure TMainForm.NotifyIcon1DblClick(Sender: TObject);
begin
Show;
end;
procedure TMainForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caNone;
Hide;
end;
procedure TMainForm.btnTermClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TMainForm.btnCloseClick(Sender: TObject);
begin
Hide;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Rever:=False;
TrayNotifyIcon1.Active:=True;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
TrayNotifyIcon1.ToolTip:=FormatDateTime('hh:mm:ss',Now);
^^^^^^^^^^^^^
此计时器虽然执行,但是不动态刷新,只有手动移开图标区域并返回可以看到刷新的值,
{if Rever then
TrayNotifyIcon1.Icon.LoadFromFile('1.ico')
else
TrayNotifyIcon1.Icon.LoadFromFile('2.ico');}
Rever:=not rever;
end;
end.
的效果,即当程序有任务执行时,可以从托盘图标Hint动态显示结果,如网络连接的传送包数。
但是当鼠标停留在托盘时,这是图标的Hint并不发生变化。
请问:
1。如何达到鼠标悬停的Hint可以动态变化呢?对于TNotifyData结构填充结构需要填充
什么内容就可以达到效果呢?
以下是测试程序unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellAPI, Menus, ComCtrls, ExtCtrls, TrayIcon, ImgList;
type
TMainForm = class(TForm)
pmiPopup: TPopupMenu;
pgclPageCtl: TPageControl;
TabSheet1: TTabSheet;
btnClose: TButton;
btnTerm: TButton;
Terminate1: TMenuItem;
Label1: TLabel;
N1: TMenuItem;
Propeties1: TMenuItem;
Timer1: TTimer;
TrayNotifyIcon1: TGrisTrayIcon;
ImageList2: TImageList;
procedure NotifyIcon1Click(Sender: TObject);
procedure NotifyIcon1DblClick(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure btnTermClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
Rever:Boolean;
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure TMainForm.NotifyIcon1Click(Sender: TObject);
begin
ShowMessage('Single click');
end;
procedure TMainForm.NotifyIcon1DblClick(Sender: TObject);
begin
Show;
end;
procedure TMainForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caNone;
Hide;
end;
procedure TMainForm.btnTermClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TMainForm.btnCloseClick(Sender: TObject);
begin
Hide;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Rever:=False;
TrayNotifyIcon1.Active:=True;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
TrayNotifyIcon1.ToolTip:=FormatDateTime('hh:mm:ss',Now);
^^^^^^^^^^^^^
此计时器虽然执行,但是不动态刷新,只有手动移开图标区域并返回可以看到刷新的值,
{if Rever then
TrayNotifyIcon1.Icon.LoadFromFile('1.ico')
else
TrayNotifyIcon1.Icon.LoadFromFile('2.ico');}
Rever:=not rever;
end;
end.