任务栏图标的闪烁(50分)

  • 主题发起人 主题发起人 poto5269
  • 开始时间 开始时间
P

poto5269

Unregistered / Unconfirmed
GUEST, unregistred user!
如何像QQ接收到消息时那样让任务栏上的图标进行闪烁呢?
 
這個很簡單
你做一個托盤程序,然后再讓某一事件成立的時候就讓某個循環成立.在這個循環中
再控制ICO的變更就行了!
 
用Timer和Shell_NotifyIcon( NIM_MODIFY, @IconData );
unit TrayIcon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus,shellapi, ImgList, ExtCtrls;
type
//----------------------------------------------------------------------
PNotifyIconData = ^TNotifyIconDataA;
TNotifyIconDataA = record
cbSize : DWORD;
Wnd : HWND;
uID : UINT;
uFlags : UINT;
uCallbackMessage : UINT;
hIcon : HICON;
szTip : array [0..63] of AnsiChar;
end;
//----------------------------------------------------------------------
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
open1: TMenuItem;
close1: TMenuItem;
N1: TMenuItem;
about1: TMenuItem;
ImageList1: TImageList;
Timer1: TTimer;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure open1Click(Sender: TObject);
procedure close1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
//-------------------------------------------------------------
Icons: array[0..1] of TIcon;
IconData: TNotifyIconData;
procedure ShowIcon;
procedure IconOnClick(var message:TMessage);
message WM_USER+1;
Procedure WMSysCommand(Var message : TMessage) ;
Message WM_SYSCOMMAND ;
//-------------------------------------------------------------
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.IconOnClick( var message: Tmessage);
var p : TPoint;
begin
if (message.lParam = WM_LBUTTONDOWN) then
begin
ShowWindow(Handle, SW_SHOW );
end;

if (message.lParam = WM_RBUTTONDOWN) then
begin
GetCursorPos(p);
popupmenu1.Popup( p.x ,p.y );
end;
end;

Procedure TForm1.WMSysCommand(Var Message : TMessage) ;
begin

if (Message.WParam = SC_MINIMIZE) then
begin
ShowIcon;
end
else
Inherited;
end;

procedure TForm1.ShowIcon;
begin
IconData.cbSize := SizeOf( IconData );
IconData.Wnd := Handle;
IconData.uID := 1;
IconData.uFlags := NIF_ICON
or NIF_MESSAGE or NIF_TIP;
IconData.uCallBackMessage := WM_USER+1;
IconData.hIcon := Icons[0].Handle;//application.Icon.Handle;
IconData.szTip := 'LANChat';
Shell_NotifyIcon( NIM_ADD, @IconData );
ShowWindow(Handle, SW_HIDE);
hide;
end;

procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Shell_NotifyIcon( NIM_DELETE, @IconData );
end;

procedure TForm1.open1Click(Sender: TObject);
begin
Form1.Show;
end;

procedure TForm1.close1Click(Sender: TObject);
begin
Form1.close;
end;

procedure TForm1.FormShow(Sender: TObject);
begin

showwindow(application.handle,sw_hide);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
for i:=0 to 1 do
begin
Icons := TIcon.Create;
ImageList1.GetIcon(i,Icons);
end;
showicon;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if IconData.hIcon = Icons[0].Handle then
IconData.hIcon := Icons[1].Handle
else
IconData.hIcon := Icons[0].Handle;
Shell_NotifyIcon( NIM_MODIFY, @IconData );
end;

end.
 
对,用定时器,设定那个图标为icon1 icon2就行了,
或者设定为icon1,一会儿又变成none
 
你自己好好看看吧

procedure TForm1.TrayShow(Sender: TObject);
//当点击托盘图标时显示或隐含主窗体
begin
PopupMenu1.AutoPopup:=False;
//设定 TNotifyIconData 的记录长度
MyTrayIcon.cbSize :=SizeOf(tnotifyicondata);
//确定调用程序的窗体句柄
MyTrayIcon.Wnd :=Handle;
//确定图标的 uID
MyTrayIcon.uID :=1;
////???我不知道这应该是多少!!!
//设定显示标记
MyTrayIcon.uFlags :=NIF_ICON or NIF_TIP or NIF_MESSAGE;
//用户自定义消息
MyTrayIcon.uCallbackMessage := WM_MYTRAYICONCALLBACK;
//托盘图标的句柄
//MyTrayIcon.hIcon := Application.Icon.Handle;
MyTrayIcon.hIcon := LoadIcon(0, IDI_WINLOGO);
//托盘图标的提示信息
MyTrayIcon.szTip :='定时导数据程序';
//向托盘中添加图标
Shell_NotifyIcon(NIM_ADD,@mytrayicon);
end;

procedure TForm1.WMMyTrayIconCallBack(var Msg: TMessage);
//处理点击托盘图标的事件,根据 WM_MOUSEMOVE 消息的不同情况产生不同的回应
var
CursorPos : TPoint;
begin
PopupMenu1.AutoPopup:=False;
case Msg.lParam of
//左键按下
WM_LBUTTONDOWN : begin
application.MainForm.BringToFront;
//窗体置前
end;
//左键双击
WM_LBUTTONDBLCLK : begin
//窗体隐含或显示
Application.MainForm.Visible := not Application.MainForm.Visible;
SetForegroundWindow(Application.Handle);
end;
//右键按下
WM_RBUTTONDOWN : begin
//显示弹出菜单
GetCursorPos(CursorPos);
PopupMenu1.Popup(CursorPos.x,CursorPos.y);
end;
end//case
end;

procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE, @MyTrayIcon);//删除托盘图标
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);//程序不在任务栏上显示
TrayShow(Application.MainForm);//显示图标
flag:=0;
end;

procedure TForm1.n_MainFromDispOrHideClick(Sender: TObject);
begin
if Application.MainForm.Visible then
begin
Application.MainForm.Hide;
end
else
begin
Application.MainForm.Show;
n_MainFromDispOrHide.Caption :='隐藏主窗体';
end;

end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
ic:TICON;
begin

if flag=0 then
flag:=1
else
flag:=0;
ic:=TICON.Create;
ImageList1.GetIcon(flag,ic);
with MyTrayIcon do
begin
cbSize := SizeOf(tnotifyicondata);
uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
uID := 0;
///该是多少啊?
Wnd := Handle;
uCallbackMessage := WM_MYTRAYICONCALLBACK;
// hIcon :=Application.Icon.Handle ;]
hicon:=ic.Handle;
end;

Shell_NotifyIcon(NIM_MODIFY,@MyTrayIcon);
///没有任何效果!
Application.MainForm.Hide;
ic.Free;
end;

end.
 
后退
顶部