请问如何在单击主窗口的最小化和关闭按钮的时候让程序缩到系统托盘中去呢?(20分)

  • 主题发起人 主题发起人 sxlyq
  • 开始时间 开始时间
S

sxlyq

Unregistered / Unconfirmed
GUEST, unregistred user!
让程序缩到托盘中我已经实现了,但是单击主窗口的最小花按钮和关闭按钮的我不知道!<br>
 
拦截wm_quit,wm_syscommand(最小化wparam为SC_MINIMIZE 或者 SC_ICON)消息进行处理.
 
我有一个方法很简单,完全代码如下:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; mux:integer;<br>&nbsp; &nbsp;procedure myminimize(sender:Tobject);<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp;application.OnMinimize:=myminimize;<br>&nbsp;mux:=0;<br>end;<br>procedure TForm1.myminimize(Sender:Tobject);<br>begin<br>//insert your minize code...<br>end;<br>procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>begin<br>&nbsp;if mux&lt;&gt;1 then<br>&nbsp;canclose:=false<br>&nbsp;else<br>&nbsp;canclose:=true;<br>&nbsp;//if you really close window ,you should set canclose to True...<br>&nbsp;//insert your close code...<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; mux:=1;<br>&nbsp; close;<br>end;<br><br>end.
 
你也可以重载组件的方法实现上述功能
 

Similar threads

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