如何让窗体最小化时只在任务托盘显示为一个小图标?(10分)

  • 主题发起人 主题发起人 asbeforelong
  • 开始时间 开始时间
A

asbeforelong

Unregistered / Unconfirmed
GUEST, unregistred user!
如何让窗体最小化时只在任务托盘显示为一个小图标?并且鼠标右击小图标时能弹出菜单?^_^ 最好给出尽量简单一点的源程序,谢谢了。^_^<br>
 
比较简单的,下载一个CoolTrayIcon控件用(第三方的)。<br><br>想自己写的话,搜搜以前的帖子,这个讨论很多的。
 
留个地址,我给你发个程序源码
 
我也想知道.我的地址:sjj1226@sohu.com 先谢谢了.
 
我也想知道<br>xieshao@183.ha.cn<br>谢谢了
 
const WM_MYTRAYICONCALLBACK = WM_USER + 1000;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ...<br>&nbsp; &nbsp; n_MainFromDispOrHide: TMenuItem;<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; MyTrayIcon : TNotifyIconData; &nbsp; //定义一个托盘图标的类<br>&nbsp; &nbsp; procedure TrayShow(Sender: TObject);<br>&nbsp; &nbsp; procedure WMMyTrayIconCallBack(var Msg : TMessage); //处理点击托盘图标的事件<br>&nbsp; &nbsp; &nbsp; message WM_MYTRAYICONCALLBACK;<br>&nbsp; &nbsp; procedure n_MainFromDispOrHideClick(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; ...<br>end;<br><br>procedure TForm1.TrayShow(Sender: TObject);<br>//当点击托盘图标时显示或隐含主窗体<br>begin<br>&nbsp; TrayBarPopMenu.AutoPopup:=False;<br>&nbsp; //设定 TNotifyIconData 的记录长度<br>&nbsp; MyTrayIcon.cbSize :=SizeOf(tnotifyicondata);<br>&nbsp; //确定调用程序的窗体句柄<br>&nbsp; MyTrayIcon.Wnd :=Handle;<br>&nbsp; //确定图标的 uID<br>&nbsp; MyTrayIcon.uID :=1;<br>&nbsp; //设定显示标记<br>&nbsp; MyTrayIcon.uFlags :=NIF_ICON or NIF_TIP or NIF_MESSAGE;<br>&nbsp; //用户自定义消息<br>&nbsp; MyTrayIcon.uCallbackMessage := WM_MYTRAYICONCALLBACK;<br>&nbsp; //托盘图标的句柄<br>&nbsp; MyTrayIcon.hIcon := Application.Icon.Handle;<br>&nbsp; //托盘图标的提示信息<br>&nbsp; MyTrayIcon.szTip :='定时导数据程序';<br>&nbsp; //向托盘中添加图标<br>&nbsp; Shell_NotifyIcon(NIM_ADD,@mytrayicon);<br>end;<br><br>procedure TForm1.WMMyTrayIconCallBack(var Msg: TMessage);<br>//处理点击托盘图标的事件,根据 WM_MOUSEMOVE 消息的不同情况产生不同的回应<br>var<br>&nbsp; CursorPos : TPoint;<br>begin<br>&nbsp; TrayBarPopMenu.AutoPopup:=False;<br>&nbsp; case Msg.lParam of<br>&nbsp; &nbsp; //左键按下<br>&nbsp; &nbsp; WM_LBUTTONDOWN : begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;application.MainForm.BringToFront; &nbsp; //窗体置前<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; //左键双击<br>&nbsp; &nbsp; WM_LBUTTONDBLCLK : begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//窗体隐含或显示<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application.MainForm.Visible := not Application.MainForm.Visible;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForegroundWindow(Application.Handle);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; //右键按下<br>&nbsp; &nbsp; WM_RBUTTONDOWN : &nbsp; begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//显示弹出菜单<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(CursorPos);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TrayBarPopMenu.Popup(CursorPos.x,CursorPos.y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;end//case<br>end;<br><br>procedure TForm1.n_MainFromDispOrHideClick(Sender: TObject);<br>begin<br>&nbsp; if Application.MainForm.Visible then<br>&nbsp; begin<br>&nbsp; &nbsp; if FormStep1.Showing Then FormStep1.Hide;<br>&nbsp; &nbsp; if FormStep2.Showing Then FormStep2.Hide;<br>&nbsp; &nbsp; Application.MainForm.Hide;<br>&nbsp; &nbsp; n_MainFromDispOrHide.Caption :='显示主窗体';<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; Application.MainForm.Show;<br>&nbsp; &nbsp; n_MainFromDispOrHide.Caption :='隐藏主窗体';<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);//程序不在任务栏上显示<br>&nbsp; TrayShow(Application.MainForm);//显示图标<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; Shell_NotifyIcon(NIM_DELETE, @MyTrayIcon);//删除托盘图标<br>end;
 
可以去看看下面的控件<br><br>CoolTrayIcon &nbsp; <br><br>自动将Form缩小为TrayIcon,可设置MinimizeToTrayIcon为True,则Form最小化时不显示在任务栏上。<br>个人认为较RxLib中的RxTrayIcon好用,而且还有源代码哦!<br><br>新增加了些属性和方法,如BitMapToIcon方法可以将位图转换为Icon使用。此外,还添加了一个新控件<br>TextTrayIcon,它直接将文字作为Tray Icon,可以设置字体、颜色等,和Timer结合起来你就可以实现动态文字的TrayIcon了,这还是满酷的嘛:-)。<br><br>完整功能. &nbsp; &nbsp;源代码: 有 <br>适用于 CB3 CB4 CB5 D2 D3 D4 D5 D6 <br><br>设置几个属性就可以了<br>有例子程序<br>http://www.playicq.com/dispdoc.php?t=&amp;id=2508
 
to:Admy<br>你有没有应用的例子,发一个给我吧<br>&nbsp;metal@win88.net<br>谢谢了!
 
楼上的<br>http://www.playicq.com/dispdoc.php?t=&amp;id=2508<br>里面的就有一个好的例子呵
 
to ken_gj:<br>&nbsp; 已发送,请查收
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
716
import
I
I
回复
0
查看
442
import
I
后退
顶部