请问怎样让程序启动后放在右下角的人物栏里?(100分)

  • 主题发起人 主题发起人 Iveny
  • 开始时间 开始时间
不介意的话用rxlib中的控件吧。<br>5秒钟解决。
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ShellAPI;<br><br>const<br>&nbsp; WM_TRAYNOTIFY = WM_USER+100; //任务区小图标自定义消息<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure TrayNotifyMessage(var Sender: TMessage); message WM_TRAYNOTIFY;<br>&nbsp; &nbsp; procedure MarkTaskBarIcon(Sender: TObject);<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; tnd : TNOTIFYICONDATA;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.MarkTaskBarIcon(Sender: TObject);<br>begin<br>&nbsp; Form1.Visible := False;<br>&nbsp; tnd.cbSize := sizeof(tnd);<br>&nbsp; tnd.Wnd := Handle;<br>&nbsp; tnd.uID := 128;<br>&nbsp; tnd.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br>&nbsp; tnd.uCallbackMessage := WM_TRAYNOTIFY;<br>&nbsp; tnd.hIcon := Application.Icon.Handle;<br>&nbsp; StrPCopy(tnd.szTip,Application.Title);<br>&nbsp; Shell_NotifyIcon(NIM_ADD,@tnd);<br>end;<br><br>procedure TForm1.TrayNotifyMessage(var Sender: TMessage);<br>begin<br>&nbsp; if Sender.LParam = WM_LBUTTONDBLCLK then<br>&nbsp; begin<br>&nbsp; &nbsp; Shell_NotifyIcon(NIM_DELETE,@tnd);<br>&nbsp; &nbsp; Form1.Visible := True;<br>&nbsp; &nbsp; Application.Restore;<br>&nbsp; &nbsp; Application.BringToFront;<br>&nbsp; end;<br>end;<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp;Application.OnMinimize := MarkTaskBarIcon;<br>end;<br><br>end.
 
控件多多,哪个好用就用哪个.
 
我不赞成这么个小程序就用控件,控件屏蔽了好多东西,不如自己编程,还可以多学点知识
 
上面的方法已经可行了。
 
我还是赞成用控件,<br>1。思夷长技以治夷。一般控件都带源码,你可以参考分析完善;<br>2。聪明的程序员用DELPHI,如果你每段程序都亲自去琢摸去写,<br>&nbsp; &nbsp;你哪来这么多的时间精力?你写个程序不会从操作系统写起吗?
 
hnzgf的程序很多地方都有,也是最经典的一个<br>就这样没错
 
可是运行那程序,什么都没有啊!都不能放在右下角的任务栏的!
 
其实对任务栏编程也很简单,但既然你没试过,我还是建议你使用控件<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 &amp; 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:PNOTIFYICONDATA;<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&lt;&gt;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.
 
如果你没学过任务栏编程,那建议你自己写一下,可以了解很多东东。<br>如果以前学过,那用控件得了,再写也不过是重复劳动,学不到东西的。
 
我想自己写写,请问可以给我个简单而又可行的例子吗?
 
你把我给你的例子堑到你的程序中就可以用,事件和代码不是都有吗?
 
到CSDN中有郝新庚改写的AHM中的一个控件,带源码,挺不错的。
 
TO: hnzgf<br>你好,你的程序是最好的解决方案,但我新建工程,把你的代码拷入,运行程序后什么都<br>没有发生啊?!右下角托盘区什么也没有!
 
我这可以呀,另外你不要直接paste过去,最好,一步一步来,把事件声明好以后,再把<br>事件代码paste过去,最好不要直接全部paste! <br>祝你好运!另外你的信箱是多少,我给你寄例子<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ShellAPI;<br><br>const<br>&nbsp; WM_TRAYNOTIFY = WM_USER+100;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure TrayNotifyMessage(var Sender: TMessage); message WM_TRAYNOTIFY;<br>&nbsp; &nbsp; procedure MarkTaskBarIcon(Sender: TObject);<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; tnd : TNOTIFYICONDATA;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp;Application.OnMinimize := MarkTaskBarIcon;<br>end;<br><br>procedure TForm1.MarkTaskBarIcon(Sender: TObject);<br>begin<br>&nbsp; &nbsp;Form1.Visible := False;<br>&nbsp; &nbsp;tnd.cbSize := sizeof(tnd);<br>&nbsp; &nbsp;tnd.Wnd := Handle;<br>&nbsp; &nbsp;tnd.uID := 128;<br>&nbsp; &nbsp;tnd.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br>&nbsp; &nbsp;tnd.uCallbackMessage := WM_TRAYNOTIFY;<br>&nbsp; &nbsp;tnd.hIcon := Application.Icon.Handle;<br>&nbsp; &nbsp;StrPCopy(tnd.szTip,Application.Title);<br>&nbsp; &nbsp;Shell_NotifyIcon(NIM_ADD,@tnd);<br>end;<br><br>procedure TForm1.TrayNotifyMessage(var Sender: TMessage);<br>begin<br>&nbsp; &nbsp;if Sender.LParam = WM_LBUTTONDBLCLK then<br>&nbsp; begin<br>&nbsp; &nbsp; Shell_NotifyIcon(NIM_DELETE,@tnd);<br>&nbsp; &nbsp; Form1.Visible := True;<br>&nbsp; &nbsp; Application.Restore;<br>&nbsp; &nbsp; Application.BringToFront;<br>&nbsp; end;<br><br>end;<br><br>end.
 
十分感谢hnzgf,我已经用你的代码实现了,谢谢!!!<br>在你的代码的基础上,我想在最小化时,托盘区的图标实现闪动的效果,请问怎样修改你的<br>代码?<br>谢谢!!!
 
其实也就是用Timer,然后放一个ImageList,不断地GetIcon,变换图标索引就可以了,<br>我可以给你一个商品控件,你一看就明白了,请于我联系,hnzgf@sina.com<br>大富翁太慢了,我好久都上不来<br><br>Good luck!
 
十分感谢hnzgf,控件我是有的,但不想用控件,如果将这功能闪动图标的功能加到你的<br>例子里,完整的例子是?谢谢!期待你的回复!<br>我的E-mail是iveny@163.net
 

Similar threads

回复
0
查看
742
不得闲
S
回复
0
查看
832
SUNSTONE的Delphi笔记
S
S
回复
0
查看
792
SUNSTONE的Delphi笔记
S
后退
顶部