其实对任务栏编程也很简单,但既然你没试过,我还是建议你使用控件<br>例如:,TrayIcon,TNotifyIcon <br>你可以在www.google.com上查询这两个关键字,可以找到许多相关的资料。<br>例如以下关于tnotifyicon:<br>TNotifyIcon 控件1.01 (Build use Delphi 3.0) 说明:<br>作用:<br>往通知区加图标,并可显示,隐藏,修改这个图标.<br><br><br>属性(properties):<br>NotifyIcon:TIcon 欲加在通知区的图标<br>IsVisible:boolean NotifyIcon是否显示的属性<br>Title:string 通知区图标上的提示(最多64个字符)<br>PopupMenu:TPopupMenu 点击通知区图标弹出的菜单 <br>PopupStyle:TPopupStyle 弹出菜单的方式 <br>TPopupStyle=Set of (Left_Click,Right_Click,Left_DbClick,Right_DbClick);<br>方法(methods): <br>ShowIcon 将图标显示在通知区上<br>HideIcon 将通知区上的图标隐藏<br>ModifyIcon 修改通知区上的图标(若IsVisible=false,则不显示出来)<br>Create(AOwner: TComponent); override; 构造方法<br>Destroy; override; 析构方法<br>事件(Events):<br>OnIconMouseDown: <br>procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of Object;<br>(<br>在Mouse点击通知区上的图标时发生,x,y为Mouse在屏幕上的坐标,<br>WhoButton=b_Left为点击左键,WhoButton=b_Right为点击右键,<br>)<br>OnIconDoubleClick: <br>procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton) of Object;<br>(<br>在Mouse双击通知区上的图标时发生,x,y为Mouse在屏幕上的坐标,<br>WhoButton=b_Left为双击左键,WhoButton=b_Right为双击右键,<br>)<br>关于Demo:<br>这个演示程序给出了TNotifyIcon的基本用法.<br><br>包含文件:<br>NotifyIcon.dcr<br>NotifyIcon.pas<br>DemoUnit.pas<br>DemoUnit.dfm<br>PopUnit.pas<br>PopUnit.dfm<br>Demo.dpr<br>Readme.txt<br><br>声明:<br>TNotifyIcon 控件 V 1.01<br>1.这是一个免费控件.<br>2.如果你使用它,请发一个E-Mail给作者,谢谢.<br>3我在Delphi3.0 & 4.0 上使用成功<br>4.若要传播它,请完全分发上述8个文件<br><br>作者 南昌大学计算系95(1) 付昱纲 1998.8.17 21:50<br>E-mail fyg@163.net <br><br>unit NotifyIcon;<br><br>interface<br><br>uses<br>Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>DsgnIntf,ShellApi,ExtCtrls,Menus;<br><br>const<br>WM_MY_Notify=WM_USER+100;<br>type<br><br>TPopupStyle=Set of (Left_Click,Right_Click,Left_DbClick,Right_DbClick);<br>TWhoButton=(b_Left,b_Right);<br>TMouseEvent=<br>procedure(Sender:TObject;x,y:Word;WhoButton:TWhoButton)<br>of Object;<br><br>//---------class TNotifyIcon---------<br>TNotifyIcon = class(TCustomControl)<br>private<br>{ Private declarations }<br>FIcon:TIcon;<br>FPda
NOTIFYICONDATA;<br>FTitle:string;<br>FIconVisible:boolean;<br>FPopupMenu:TPopupMenu;<br>FPopupStyle:TPopupStyle;<br>FOnIconMouseDown:TMouseEvent;<br>FOnIconDoubleClick:TMouseEvent;<br>procedure SetIcon(Icon:TICON);<br>procedure SetTitle(NewTitle:string);<br>function IsShowing:boolean;<br>procedure ShowIt(Accept:boolean);<br>procedure NotifyIconClick(var msg : TMessage);<br>Message WM_My_Notify;<br>protected<br>{ Protected declarations }<br>public<br>{ Public declarations }<br>property IsVisible:boolean read IsShowing write ShowIt;<br>constructor Create(AOwner: TComponent); override;<br>procedure ShowIcon;<br>procedure HideIcon;<br>destructor Destroy; override;<br>procedure ModifyIcon(NewIcon:TIcon);<br>procedure Paint;override;<br>published<br>{ Published declarations }<br>property Height default 33;<br>property Width default 33;<br>property NotifyIcon:TIcon read FIcon write SetIcon;<br>property Title:string read FTitle write SetTitle ;<br>property OnIconDoubleClick:TMouseEvent<br>read FOnIconDoubleClick write FOnIconDoubleClick;<br>property OnIconMouseDown:TMouseEvent<br>read FOnIconMouseDown write FOnIconMouseDown;<br>property PopupMenu:TPopupMenu read FPopupMenu write FPopupMenu;<br>property PopupStyle:TPopupStyle read FPopupStyle<br>write FPopupStyle default [];<br>end;<br><br>procedure Register;<br><br>implementation<br><br>procedure Register;<br>begin<br>RegisterComponents('MyControl', [TNotifyIcon]);<br>end;<br><br>procedure TNotifyIcon.ShowIt(Accept:boolean);<br>begin<br>if Accept=true then ShowIcon<br>else HideIcon;<br>end;<br><br>procedure TNotifyIcon.Paint;<br>begin<br>if (csDesigning in ComponentState) then<br>begin<br>Width:=33;<br>Height:=33;<br>With Canvas do<br>begin<br>Brush.Color:=clInfoBk;<br>Ellipse(0,0,Self.Width,Self.Height);<br>Font.Color:=clBlue;<br>Brush.Style:=bsClear;<br>FloodFill(5,5,clInfoBk,fsBorder);<br>Brush.Color:=clInfoBk;<br>TextOut(3,Self.Height div 2-6,'Notify');<br>end<br>end;<br>end;<br><br>procedure TNotifyIcon.NotifyIconClick(var msg : TMessage);<br>var p:TPoint;<br>begin<br>try<br>case msg.LParam of<br>WM_LBUTTONDOWN:<br>begin<br>GetCursorPos(p);<br>if Left_Click in FPopupStyle then<br>begin<br>SetForegroundWindow(ParentWindow);<br>FPopupMenu.Popup(p.x,p.y);<br>end;<br>if Assigned(FOnIconMouseDown) then<br>begin<br>FOnIconMouseDown(Self,p.x,p.y,b_Left);<br>end;<br>end;<br>WM_RBUTTONDOWN:<br>begin<br>GetCursorPos(p);<br>if Right_Click in FPopupStyle then<br>begin<br>SetForegroundWindow(ParentWindow);<br>FPopupMenu.Popup(p.x,p.y);<br>end;<br>if Assigned(FOnIconMouseDown) then<br>begin<br>FOnIconMouseDown(Self,p.x,p.y,b_Right);<br>end;<br>end;<br>WM_LBUTTONDBLCLK:<br>begin<br>GetCursorPos(p);<br>if Left_DbClick in FPopupStyle then<br>begin<br>SetForegroundWindow(ParentWindow);<br>FPopupMenu.Popup(p.x,p.y);<br>end;<br>if Assigned(FOnIconDoubleClick) then<br>begin<br>FOnIconDoubleClick(Self,p.x,p.y,b_Left);<br>end;<br>end;<br>WM_RBUTTONDBLCLk:<br>begin<br>GetCursorPos(p);<br>if Right_Click in FPopupStyle then<br>begin<br>SetForegroundWindow(ParentWindow);<br>FPopupMenu.Popup(p.x,p.y);<br>end;<br>if Assigned(FOnIconDoubleClick) then<br>begin<br>FOnIconDoubleClick(Self,p.x,p.y,b_Right);<br>end;<br>end;<br>end;<br>except<br>end;<br>end;<br><br>function MAKELANGID(p, s:word):Cardinal;<br>begin<br>result:= (((s)shl 10) or(p));<br>end;<br><br>constructor TNotifyIcon.Create(AOwner: TComponent);<br>begin<br>try<br>inherited Create(AOwner);<br>FIcon:=TIcon.Create;<br>Height:=36;<br>Width:=36;<br>Visible:=false;<br>FTitle:='Welcome';<br>FIconVisible:=false;<br>//-------------set tray info---------<br>ParentWindow:=TWinControl(AOwner).Handle;<br>New(Fpda);<br>With FPda^ do<br>begin<br>uCallbackMessage:=WM_MY_Notify;<br>cbsize:=SizeOf(FPda^);<br>uID:=200;<br>wnd:=Handle;<br>uFlags:=NIF_ICON+NIF_Tip+NIF_MESSAGE;<br>end;<br><br>if (csDesigning in ComponentState) then<br>begin<br>if GetUserDefaultLCID = MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED) then<br>Application.MessageBox(<br>'Write by 南昌大学 付昱纲'#13#13'E-mail:fyg@163.net'#13#13' 1998.8.17',<br>'TNotifyIcon 控件 V 1.01',MB_OK+ MB_ICONINFORMATION)<br>else<br>Application.MessageBox(<br>'Write by NanChang University FuYuGang'#13#13'E-mail:fyg@163.net'#13#13' 1998.8.17',<br>'TNotifyIcon Component V 1.01',MB_OK+ MB_ICONINFORMATION);<br>end;<br>except<br>ShowMessage('TNotifyIcon Create error');<br>end;<br>end;<br><br>procedure TNotifyIcon.SetIcon(Icon:TICON);<br>begin<br>FIcon.Assign(Icon);<br>end;<br><br>procedure TNotifyIcon.ShowIcon;<br>begin<br>try<br>if FIcon.Handle=0 then<br>begin<br>Exit;<br>end;<br>if FIcon.Handle<>FPda^.hIcon then<br>HideIcon;<br>if FIconVisible=false then<br>begin<br>FPda^.hIcon:=FIcon.handle;<br>FIconVisible:=true;<br>Shell_NotifyIcon(NiM_ADD,FPda);<br>end;<br>except<br>ShowMessage('TNotifyIcon Show Error ');<br>end;<br>end;<br><br>procedure TNotifyIcon.HideIcon;<br>begin<br>try<br>if FIconVisible then<br>begin<br>FIconVisible:=false;<br>Shell_NotifyIcon(NiM_DELETE,FPda);<br>end;<br>except<br>ShowMessage('TNotifyIcon Hide Error');<br>end;<br>end;<br><br>procedure TNotifyIcon.SetTitle(NewTitle:string);<br>begin<br>FTitle:=NewTitle;<br>StrCopy(FPda^.szTip,PChar(FTitle));<br>if FIconVisible then<br>begin<br>HideIcon;<br>ShowIcon;<br>end;<br>end;<br><br>destructor TNotifyIcon.Destroy;<br>begin<br>try<br>HideIcon;<br>Dispose(FPda);<br>FIcon.Free;<br>inherited Destroy;<br>except<br>ShowMessage('TNotifyIcon Destroy Error');<br>end;<br>end;<br><br>procedure TNotifyIcon.ModifyIcon(NewIcon:TIcon);<br>begin<br>try<br>SetIcon(NewIcon);<br>FPda^.hIcon:=FIcon.handle;<br>if FIconVisible then<br>Shell_NotifyIcon(NiM_Modify,FPda);<br>except<br>ShowMessage('TNotifyIcon Modify Error');<br>end;<br>end;<br><br>function TNotifyIcon.IsShowing:boolean;<br>begin<br>Result:=FIconVisible;<br>end;<br><br>end.