怎样让程序最小化后到状态栏中?************************************************************************ 像WINAMP、杀毒软件那样请有详细代码,我比较笨。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 application.Minimize,如果你要是最小化到系统托盘,就找个组件来实现吧. 组件在www.51delphi.com有下.rxlib组件.taryicon unit Unit1; interface { 记住在uses部分中包括 ShellAPI} uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ShellAPI, StdCtrls; {自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息} {自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息} const MY_MESSAGE = WM_USER + 100; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormPaint(Sender: TObject); private procedure OnIconNotify(var Message: TMessage); message MY_MESSAGE; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} {当小图标捕捉到鼠标事件时进入此过程} {当小图标捕捉到鼠标事件时进入此过程} procedure TForm1.OnIconNotify(var Message: TMessage); const Busy: Boolean = false; begin if not Busy then begin Busy := true; if Message.LParam=WM_LBUTTONDOWN then if Application.MessageBox('Are you sure', 'Exit', MB_YESNO)=IDYES then Close; Busy := false; end; end; {当主Form建立时通知Windows加入小图标} procedure TForm1.FormCreate(Sender: TObject); var nid: TNotifyIconData; begin nid.cbSize := sizeof(nid); // nid变量的字节数 nid.Wnd := Handle; // 主窗口句柄 nid.uID := -1; // 内部标识,可设为任意数 nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?nid.szTip := 'This is a test application'; // 提示字符串 nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息 nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?if not Shell_NotifyIcon(NIM_ADD, @nid) then begin ShowMessage('Failed!'); Application.Terminate; end; {将程序的窗口样式设为TOOL窗口,可避免在任务条上出现} SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW); end; {程序被关闭时通知Windows去掉小图标} procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var nid: TNotifyIconData; begin nid.cbSize := sizeof(nid); // nid变量的字节数 nid.cbSize := sizeof(nid); // nid变量的字节数 nid.uID := -1; //内部标识,与加入小图标时的数一致 nid.Wnd := Handle; //主窗口句柄 Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标 Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标 end; {主窗口初始化完毕并显示时将激活Paint重画事件,此时将主窗口隐藏} procedure TForm1.FormPaint(Sender: TObject); begin Hide; end; end. to zhaozhe(哲) :下面的代码是对cg1120(代码最优化-§雪是冷的,人是暖的§) 前辈代码的一点修正~不好意思借花献佛了~1.加{$J+}编译开关,否则delphi不支持const定义下的变量的修改2.修改后的代码在对图标点击时可以还原.3.将nid.uID := -1;改为0,避免错误: [Error] Constant expression violates subrange bounds4.去掉paint事件,这样form始终将处于hide状态.unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,shellAPI, StdCtrls;const MY_MESSAGE = WM_USER + 100;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } procedure OnIconNotify(var Message: TMessage);message MY_MESSAGE; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}{当小图标捕捉到鼠标事件时进入此过程}{当小图标捕捉到鼠标事件时进入此过程}{$J+}procedure TForm1.OnIconNotify(var Message: TMessage);constBusy: Boolean = false;beginif not Busy then begin Busy := true;if Message.LParam=WM_LBUTTONDOWN thenApplication.Restore;Busy := false;end;end;{当主Form建立时通知Windows加入小图标}procedure TForm1.FormCreate(Sender: TObject);varnid: TNotifyIconData;begin nid.cbSize := sizeof(nid); // nid变量的字节数 nid.Wnd := Handle; // 主窗口句柄 nid.uID := 0; // 内部标识,可设为任意数 nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?//nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指? nid.szTip := 'This is a test application'; // 提示字符串 nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息 nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有? if not Shell_NotifyIcon(NIM_ADD, @nid) then begin ShowMessage('Failed!'); Application.Terminate; end; {将程序的窗口样式设为TOOL窗口,可避免在任务条上出现} SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);end;{程序被关闭时通知Windows去掉小图标}procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var nid: TNotifyIconData;begin nid.cbSize := sizeof(nid); // nid变量的字节数 nid.cbSize := sizeof(nid); // nid变量的字节数nid.uID := 0; //内部标识,与加入小图标时的数一致 -1nid.Wnd := Handle; //主窗口句柄 Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标 end; {主窗口初始化完毕并显示时将激活Paint重画事件,此时将主窗口隐藏} procedure TForm1.Button1Click(Sender: TObject);begin Application.Minimize;end;end. Sample页下的TTrayIcon控件,自己设置一下 各位大版们,小弟有急事相问,不胜感激! bde 连接sql 2000 我开始用Delphi进行PCI7501板子的控制编程,我有问题要问各位高手!!!!!!! OnExit有问题? 請教,BDE問題:"Corrupt file-other than header" interface not supported 是什么异常? 如何锁定刷新频率,进入游戏也不改变。 谁有金山词霸? 两个变量计算再比较,用sql和delphi写要怎么样? 如何从记录集中取数据!! 怎么样才能知道一个文件的大小?(在线等待) DELPHI只能作数据库吗?
rxlib组件.taryicon
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
ShellAPI, StdCtrls; {自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}
{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}
const MY_MESSAGE = WM_USER + 100; type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormPaint(Sender: TObject);
private
procedure OnIconNotify(var Message: TMessage);
message MY_MESSAGE;
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.DFM}
{当小图标捕捉到鼠标事件时进入此过程}
{当小图标捕捉到鼠标事件时进入此过程}
procedure TForm1.OnIconNotify(var Message: TMessage);
const
Busy: Boolean = false;
begin
if not Busy then begin
Busy := true;
if Message.LParam=WM_LBUTTONDOWN then
if Application.MessageBox('Are you sure',
'Exit', MB_YESNO)=IDYES then Close;
Busy := false;
end;
end; {当主Form建立时通知Windows加入小图标}
procedure TForm1.FormCreate(Sender: TObject);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.Wnd := Handle; // 主窗口句柄
nid.uID := -1; // 内部标识,可设为任意数
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?nid.szTip := 'This is a test application'; // 提示字符串
nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?if not Shell_NotifyIcon(NIM_ADD, @nid) then begin
ShowMessage('Failed!');
Application.Terminate;
end;
{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end; {程序被关闭时通知Windows去掉小图标}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.uID := -1; //内部标识,与加入小图标时的数一致
nid.Wnd := Handle; //主窗口句柄
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
end; {主窗口初始化完毕并显示时将激活Paint重画事件,此时将主窗口隐藏}
procedure TForm1.FormPaint(Sender: TObject);
begin
Hide;
end; end.
下面的代码是对cg1120(代码最优化-§雪是冷的,人是暖的§) 前辈代码的一点修正~不好意思借花献佛了~1.加{$J+}编译开关,否则delphi不支持const定义下的变量的修改
2.修改后的代码在对图标点击时可以还原.
3.将nid.uID := -1;改为0,避免错误:
[Error] Constant expression violates subrange bounds
4.去掉paint事件,这样form始终将处于hide状态.unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellAPI, StdCtrls;const MY_MESSAGE = WM_USER + 100;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure OnIconNotify(var Message: TMessage);message MY_MESSAGE;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
{当小图标捕捉到鼠标事件时进入此过程}{当小图标捕捉到鼠标事件时进入此过程}{$J+}
procedure TForm1.OnIconNotify(var Message: TMessage);
const
Busy: Boolean = false;
begin
if not Busy then begin
Busy := true;
if Message.LParam=WM_LBUTTONDOWN then
Application.Restore;
Busy := false;
end;
end;{当主Form建立时通知Windows加入小图标}
procedure TForm1.FormCreate(Sender: TObject);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.Wnd := Handle; // 主窗口句柄
nid.uID := 0; // 内部标识,可设为任意数
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
//nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指? nid.szTip := 'This is a test application'; // 提示字符串
nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有? if not Shell_NotifyIcon(NIM_ADD, @nid) then
begin
ShowMessage('Failed!');
Application.Terminate;
end;
{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end;{程序被关闭时通知Windows去掉小图标}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.uID := 0; //内部标识,与加入小图标时的数一致 -1
nid.Wnd := Handle; //主窗口句柄
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
end; {主窗口初始化完毕并显示时将激活Paint重画事件,此时将主窗口隐藏}
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.Minimize;
end;end.