如何实现托盘程序的图标在屏幕右下角闪烁

liujie78 2004-11-30 01:14:54
DELPHI托盘程序我已实现,但无法让其图标闪烁,望各位仁兄指点一二。
...全文
313 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zninger 2004-11-30
  • 打赏
  • 举报
回复
unit Unit1;

interface

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

const
mousemsg = wm_user + 1;
iid = 100;

type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
Timer1: TTimer;
procedure mousemessage(var message: tmessage); message mousemsg;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
ntida: TNotifyIconDataA;
Index:integer;

implementation

{$R *.DFM}

procedure TForm1.mousemessage(var message: tmessage);
var
mousept: TPoint;begin
inherited;
if message.LParam = wm_rbuttonup then
begin
getcursorpos(mousept);
popupmenu1.popup(mousept.x, mousept.y);
end;
if message.LParam = wm_lbuttonup then
begin
ShowWindow(Handle, SW_SHOW);
ShowWindow(Application.handle, SW_SHOW);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW AND NOT WS_EX_APPWINDOW));
end;
message.Result := 0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ntida.cbSize := sizeof(tnotifyicondataa);
ntida.Wnd := handle;
ntida.uID := iid;
ntida.uFlags := nif_icon + nif_tip + nif_message;
hIcon.ÍszTip²ÎÊý¶¼ÓÐЧ
ntida.uCallbackMessage := mousemsg;
ntida.hIcon := Application.Icon.handle;
ntida.szTip := 'Icon';
shell_notifyicona(NIM_ADD, @ntida);
Index:=0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
FpNotify:_NOTIFYICONDATAA;
ic:TIcon;
begin
if Index =0 then
begin
Application.Icon.LoadFromFile('1.ico');
Index:=1;
end else
begin
Application.Icon.LoadFromFile('2.ico');
Index:=0;
end;
Icon.Assign(Application.Icon);
ntida.cbSize := sizeof(tnotifyicondataa);
ntida.Wnd := handle;
ntida.uID := iid;
ntida.uFlags := nif_icon + nif_tip + nif_message;
ntida.uCallbackMessage := mousemsg;
ntida.hIcon := Application.Icon.handle;
ntida.szTip := 'Icon';
shell_notifyicona(NIM_modify, @ntida);
end;

end.
liujie78 2004-11-30
  • 打赏
  • 举报
回复
我试了,可还是不好用,请问CM_nTaskIcoMsg是什么消息?
hawk_js 2004-11-30
  • 打赏
  • 举报
回复
MARK
bee2518 2004-11-30
  • 打赏
  • 举报
回复
以下这段程序是在托盘区每隔一段时间改变一次图标

procedure TFormMain.Timer1Timer(Sender: TObject);
begin
if Index=0 then
begin
Application.Icon.Handle:=LoadIcon(HInstance,'NEXT');
Index:=1;
end else
begin
Application.Icon.Handle := LoadIcon(HInstance,'MAINICON');
Index:=0;
end;
Icon.Assign(Application.Icon);
with FpNotify^ do
begin
Wnd := Handle;
uID := 0;
uFlags := NIF_ICON + NIF_MESSAGE + NIF_TIP;
hIcon := Application.Icon.Handle;
uCallbackMessage := CM_nTaskIcoMsg;
StrPCopy(szTip,Tips);
end;
Shell_NotifyIcon(NIM_MODIFY, FpNotify);
end;
bee2518 2004-11-30
  • 打赏
  • 举报
回复
CoolTrayIcon这个控件里面有个属性是可以使图标闪烁的。
你可以下载其看看源代码
bee2518 2004-11-30
  • 打赏
  • 举报
回复
用定时器,设定那个图标为icon1 icon2就行了,或者设定为icon1,一会儿又变成none

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧