怎样才能做出像NetAnts那样的自动最小化至托盘区呢?(50分)

Z

ZeeGee

Unregistered / Unconfirmed
GUEST, unregistred user!
我试了好几次,都不理想。是响应Application.OnReize还是Form.OnResize呢?
 
在OnCreate置一个变量First为True。<br>在OnActivate中如果First为真,就将窗口Hide了,然后再置First为false。
 
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>
 
响应TApplication的OnMinimize事件,这样就会向任务条缩小。<br>使用Minimize过程来最小化程序。
 
你的邮箱是多少, 我做了个发给你。
 
http://www.ocloud.com/download/softdown.php?softid=443&amp;url=http://61.132.118.165/soft/delphi/Delphi3/adfComponents.zip<br><br>这是一组控件<br>中的有一个控件就可以实现的说的功能<br>而且有Demo<br><br>给我分吧<br><br>
 
可以在Mainform里面截WM_SYSCOMMAND或WM_SIZE消息
 
&gt;&gt;这个问题好象不是怎样在托盘区显示图标,而是在程序最小化时向着托盘区缩小,<br>&gt;&gt;而不是向着任务条缩小!<br><br>???<br><br>我写的程序就是托盘区显示图标<br>我的代码是从已经写好的程序里面摘出来的,绝对没有问题!!<br><br>这个功能用不着组件,用我写的代码足矣,
 
you can use<br>&nbsp; Application.Minimize;
 
怎样响应TApplication的OnMinimize事件,使窗口向任务条缩小。
 
我有源程序,怎么发布呢?
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部