任务栏编程中的loadico怎么用(100分)

  • 主题发起人 主题发起人 lizhi00
  • 开始时间 开始时间
L

lizhi00

Unregistered / Unconfirmed
GUEST, unregistred user!
我总是不能加上图标,不知为什么。<br>哪位给个详细的例子。<br>多谢!
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics,<br>&nbsp; Controls, Forms, Dialogs, ExtCtrls, ShellAPI;<br><br>const<br>&nbsp; WM_TRAYNOTIFY=WM_USER+1;//定义通知消息<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; procedure WndProc(var Msg: TMessage); override;<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; nd0, nd1:NotifyIconData;<br>&nbsp; hs:array[0..9]of LongWord;<br><br>implementation<br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; //加载Icon0..Icon9这10个图标资源,<br>并且保存它们的句柄。<br>&nbsp; //图标Icon0..Icon9分别对应与0..9这9个数字。<br>&nbsp; hs[0]:=LoadIcon(hInstance, 'Icon0');<br>&nbsp; hs[1]:=LoadIcon(hInstance, 'Icon1');<br>&nbsp; hs[2]:=LoadIcon(hInstance, 'Icon2');<br>&nbsp; hs[3]:=LoadIcon(hInstance, 'Icon3');<br>&nbsp; hs[4]:=LoadIcon(hInstance, 'Icon4');<br>&nbsp; hs[5]:=LoadIcon(hInstance, 'Icon5');<br>&nbsp; hs[6]:=LoadIcon(hInstance, 'Icon6');<br>&nbsp; hs[7]:=LoadIcon(hInstance, 'Icon7');<br>&nbsp; hs[8]:=LoadIcon(hInstance, 'Icon8');<br>&nbsp; hs[9]:=LoadIcon(hInstance, 'Icon9');<br><br>&nbsp; //填充NotifyIconData记录型变量nd0<br>&nbsp; nd0.cbSize := sizeof(NotifyIconData);<br>&nbsp; nd0.Wnd := handle;<br>&nbsp; nd0.uID := 0;<br>&nbsp; nd0.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br>&nbsp; nd0.uCallbackMessage := WM_TRAYNOTIFY;<br>&nbsp; nd0.hIcon := hs[0];<br>&nbsp; StrPLCopy(nd0.szTip, 'Hello, World!', 63);<br><br>&nbsp; //填充NotifyIconData记录型变量nd1<br>&nbsp; nd1.cbSize := sizeof(NotifyIconData);<br>&nbsp; nd1.Wnd := handle;<br>&nbsp; nd1.uID := 1;<br>&nbsp; nd1.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br>&nbsp; nd1.uCallbackMessage := WM_TRAYNOTIFY;<br>&nbsp; nd1.hIcon := hs[0];<br>&nbsp; StrPLCopy(nd1.szTip, 'Simon Loves Daisy', 63);<br><br>&nbsp; //在任务栏状态区添加图标<br>&nbsp; Shell_NotifyIcon(NIM_ADD, @nd0);<br>&nbsp; Shell_NotifyIcon(NIM_ADD, @nd1);<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; st:SystemTime;<br>begin<br>&nbsp; //每秒钟更新一次图标:图标0显示秒数的十位,<br>图标1显示秒数的个位。<br>&nbsp; GetLocalTime(st);<br>&nbsp; nd0.hIcon := hs[st.wSecond div 10];<br>&nbsp; nd1.hIcon := hs[st.wSecond mod 10];<br>&nbsp; //修改任务栏状态区的图标<br>&nbsp; Shell_NotifyIcon(NIM_MODIFY, @nd0);<br>&nbsp; Shell_NotifyIcon(NIM_MODIFY, @nd1);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; //将图标从任务栏状态区删除<br>&nbsp; Shell_NotifyIcon(NIM_DELETE, @nd0);<br>&nbsp; Shell_NotifyIcon(NIM_DELETE, @nd1);<br>end;<br><br>//处理 通知消息<br>procedure TForm1.WndProc(var Msg: TMessage);<br>var<br>&nbsp; IconID:integer;<br>&nbsp; pt:TPOINT;<br>begin<br>&nbsp; if msg.Msg = WM_TRAYNOTIFY then<br>&nbsp; begin<br>&nbsp; {<br>&nbsp; 在通知消息中,wParam参数为图标的uID,<br>&nbsp; lParam参数为鼠标事件的类型。<br>&nbsp; }<br>&nbsp; &nbsp; iconID := msg.WParam;<br>&nbsp; &nbsp; //获取鼠标的在屏幕上的位置<br>&nbsp; &nbsp; GetCursorPos(pt);<br><br>&nbsp; //通知消息的处理的基本框架结构如下:<br>&nbsp; &nbsp; case msg.lParam of<br>&nbsp; &nbsp; &nbsp; WM_LBUTTONDOWN:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; //鼠标右键被按下<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_RBUTTONDOWN:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; //鼠标左键被按下<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_LBUTTONUP:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; //释放鼠标左键<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_RBUTTONUP:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; //释放鼠标右键<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_MOUSEMOVE:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; //鼠标在图标上移动<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_LBUTTONDBLCLK:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; //鼠标左键双击<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_RBUTTONDBLCLK:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; //鼠标右键双击<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end; //end case<br>&nbsp; end<br>&nbsp; else//调用父类的WndProc方法处理其它消息<br>&nbsp; &nbsp; inherited;<br>end;<br><br>end.<br>有些东西,你就自己加好了。希望这些对你有用了。<br>上面只是我做的小试验,你看看。行不行了。
 
后退
顶部