TextTrayIcon 控件,效果不错,可以在 trayIcon里显示自定义文字。
解决方案 »
- 怎么样给ListView控件的Items填加下拉框。
- 求高手解惑
- 这是什么意思呀?
- 一键统计.........100分 ado access,
- 有人用过ASTA这个控件吗?
- 有什么办法把canvas上的图形清空?
- 再加100分 http://expert.csdn.net/Expert/topic/1841/1841448.xml?temp=.7633783
- wise 9.02中怎样来设置别名的路径呢,100分?
- 湖南的delphi爱好者请进:)
- 请问哪儿有报表控件和自动生成帮助的控件下载,谢谢!
- 我做了一个bpl,可是当使用这个bpl编译时还需要我bpl中的dcu,有没有办法把duc全包括到bpl中或一个文件中,否则duc太多了
- 菜鸟求救:怎样用datetimepicker获取系统时间,并怎样使他的显示时间少两天。增50分
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, Registry, ShellAPI, Jpeg, StdCtrls;const
MY_MESSAGE=WM_USER+100;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
procedure OnIconNotify(var Message:TMessage);Message MY_MESSAGE;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1:TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
var
nid:NotifyIconData;
begin
nid.cbSize:=sizeof(nid);
nid.Wnd:=handle;
nid.uID:=1;
nid.uCallbackMessage:=MY_MESSAGE;
nid.hIcon:=application.Icon.Handle;
nid.szTip:='OK!';
nid.uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;
if not shell_NotifyIcon(NIM_ADD,@nid) then Application.Terminate;
form1.Hide;
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
end;
end;procedure TForm1.OnIconNotify(var Message: TMessage);
var
nid:NotifyIconData;
begin
if not(Message.LParam=WM_LBUTTONDOWN) then exit;
nid.cbSize:=sizeof(nid);
nid.uid:=1;
nid.Wnd:=handle;
Shell_NotifyIcon(NIM_DELETE,@nid);
end;end.
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
ShellAPI, StdCtrls; {自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}
{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}
const MY_MESSAGE = WM_USER + 100; type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormPaint(Sender: TObject);
private
procedure OnIconNotify(var Message: TMessage);
message MY_MESSAGE;
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.DFM}
{当小图标捕捉到鼠标事件时进入此过程}
{当小图标捕捉到鼠标事件时进入此过程}
procedure TForm1.OnIconNotify(var Message: TMessage);
const
Busy: Boolean = false;
begin
if not Busy then begin
Busy := true;
if Message.LParam=WM_LBUTTONDOWN then
if Application.MessageBox('Are you sure',
'Exit', MB_YESNO)=IDYES then Close;
Busy := false;
end;
end; {当主Form建立时通知Windows加入小图标}
procedure TForm1.FormCreate(Sender: TObject);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.Wnd := Handle; // 主窗口句柄
nid.uID := -1; // 内部标识,可设为任意数
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?nid.szTip := 'This is a test application'; // 提示字符串
nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?if not Shell_NotifyIcon(NIM_ADD, @nid) then begin
ShowMessage('Failed!');
Application.Terminate;
end;
{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end; {程序被关闭时通知Windows去掉小图标}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.uID := -1; //内部标识,与加入小图标时的数一致
nid.Wnd := Handle; //主窗口句柄
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
end; {主窗口初始化完毕并显示时将激活Paint重画事件,此时将主窗口隐藏}
procedure TForm1.FormPaint(Sender: TObject);
begin
Hide;
end; end.
//下面是我程序的代码片段
const WM_MYTRAYICONCALLBACK=WM_USER+1000;
************
private
{ Private declarations }
MyTrayIcon:TNotifyIconData;
procedure WMMyTrayIconCallBack(var Msg:TMessage);
message WM_MYTRAYICONCALLBACK;
************
procedure Tmain.WMMyTrayIconCallBack(var Msg:TMessage);
var CursorPos:TPoint;
begin
case Msg.LParam of
WM_RBUTTONDOWN: begin
if passed And Not(main.Visible) then
begin
GetCursorPos(CursorPos);
PopupMenu1.Popup(CursorPos.X,CursorPos.Y);
end;
end;
WM_LBUTTONDOWN: begin
if passed then main.Visible:=Not(main.Visible);
end;
end;
end;
***************************
在form的oncreate事件里
MyTrayIcon.cbSize:=SizeOf(TNotifyIconData);
MyTrayIcon.Wnd:=Handle;
MyTrayIcon.uID:=1;
MyTrayIcon.uFlags:=NIF_ICON or NIF_TIP or nif_MESSAGE;
MyTrayIcon.uCallbackMessage:=WM_MYTRAYICONCALLBACK;
MyTrayIcon.hIcon:=Application.Icon.Handle;
MyTrayIcon.szTip:='青苔小工具V1.0版';
Shell_NotifyIcon(NIM_ADD,@MyTrayIcon);
*************************、
在from的onDestroy事件里
Shell_NotifyIcon(NIM_DELETE,@MyTrayIcon);
// 名称:FillDataStructure
// 说明:填写IconData的值以便显示不同的位图
// 返回:无
// 编程:,2001-05-18 //程序的托盘定义
//==================================================================
procedure TfrmSEND.FillDataStructure;
begin
with IconData do begin
cbSize := sizeof(TNOTIFYICONDATA);
wnd :=Self.Handle ;
uID := 0; // is not passed in with message so make it 0
uFlags := NIF_MESSAGE + NIF_ICON + NIF_TIP;
hIcon := Self.Icon.Handle;
StrPCopy(szTip,'NET SEND短信发送程序');//托盘图标标题
uCallbackMessage := WM_TOOLTRAYICON;
end;
end;
Shell_NotifyIcon(NIM_DELETE,@IconData);//删除托盘图标Shell_NotifyIcon(NIM_Add,@IconData); //添加托盘图标
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ShellAPI, StdCtrls;const
MY_MESSAGE=WM_USER+100;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure OnMinimize(var Message:TMessage);Message WM_SYSCOMMAND;
procedure OnIconNotify(var Message:TMessage);Message MY_MESSAGE;
public
procedure toshow;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.OnIconNotify(var Message: TMessage);
var
Busy:Boolean;
begin
if Message.LParam=WM_LBUTTONDOWN then TOshow;
end;procedure TForm1.OnMinimize(var Message: TMessage);
var
nid:NotifyIconData;
begin
case Message.WParam of
SC_CLOSE: form2.Close;
SC_MINIMIZE:
begin
nid.cbSize:=sizeof(nid);
nid.Wnd:=handle;
nid.uID:=1;
nid.uCallbackMessage:=MY_MESSAGE;
nid.hIcon:=application.Icon.Handle;
nid.szTip:='OK!';
nid.uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;
if not shell_NotifyIcon(NIM_ADD,@nid) then
begin
showmessage('Failed!');
Application.Terminate; //结束进程
end;
form1.Hide;
end;
else inherited;
end;
// SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); //设置Application的位置
end;procedure TForm1.toshow;
var
nid:NotifyIconData;
begin
nid.cbSize:=sizeof(nid);
nid.uid:=1;
nid.Wnd:=handle;
Shell_NotifyIcon(NIM_DELETE,@nid);
form1.show;
end;