如何将delphi程序最小化到系统托盘中? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button1Click(Sender: TObject); private procedure OnIconNotify(var Message: TMessage);message MY_MESSAGE; public { Public declarations } end;var Form1: TForm1;procedure AddSystray(hnd:HWnd);procedure DelSystray(hnd:HWnd);implementation{$R *.dfm}procedure AddSystray(hnd:HWnd);var nid: TNotifyIconData;begin nid.cbSize := sizeof(nid); // nid变量的字节数 nid.Wnd := hnd; // 主窗口句柄 nid.uID := 11; // 内部标识,可设为任意数 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('Add systray Failed!'); end;end;procedure DelSystray(hnd:HWnd);var nid: TNotifyIconData;begin nid.cbSize := sizeof(nid); // nid变量的字节数 nid.cbSize := sizeof(nid); // nid变量的字节数 nid.uID := 11; //内部标识,与加入小图标时的数一致 nid.Wnd := hnd; //主窗口句柄 Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标 Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标end;{ TForm1 }procedure TForm1.OnIconNotify(var Message: TMessage);var Busy: Boolean;begin Busy:=False; if not Busy then begin Busy := true; if Message.LParam=WM_LBUTTONDOWN then begin if Application.MessageBox('Are you sure','Exit', MB_YESNO)=IDYES then show; end; end; Busy := false;end;procedure TForm1.FormCreate(Sender: TObject);begin AddSystray(handle);end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin DelSystray(handle);end;procedure TForm1.Button1Click(Sender: TObject);begin hide;end;end. unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,ShellAPI, StdCtrls, Menus;const WM_NID=WM_USER+1000;type TForm2 = class(TForm) PopupMenu1: TPopupMenu; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } NotifyIcon:TNotifyIconData; procedure WMNID(var msg:TMessage);message WM_NID; public { Public declarations } end;var Form2: TForm2;implementation{$R *.dfm}procedure TForm2.FormCreate(Sender: TObject);Begin //NotifyIcon为全局变量,在程序的开头已经定义了 with NotifyIcon do begin cbSize:=SizeOf(TNotifyIconData); Wnd:=Handle; //指向当前窗体Form1的句柄 uID:=1; uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP; uCallBackMessage:=WM_NID; hIcon:=Application.Icon.Handle; szTip:='张家恶少';end;//把设置好的变量NotifyIcon加入到系统中以便处理 Shell_NotifyIcon(NIM_ADD,@NotifyIcon);End;procedure tform2.WMNID(var msg:TMessage);begin case msg.LParam of WM_LBUTTONUp:Form2.Visible:=not Form2.Visible; //WM_RBUTTONUP: ShowMessage('您点击的是右键'); WM_RBUTTONUP: begin PopupMenu1.Popup(mouse.CursorPos.X,mouse.CursorPos.Y); end; End;End;end. 如果你用RX系统控件的话就很简单原来我用系统API作,但结果却不如用RxTrayIcon感觉效果好而且它也有例子,很快就可以搞定 比如RX的RXtrayIcon就可以轻松搞定,而且支持鼠标事件 怎样让用delphi7 开发的代码自动排列成无序? 请高手帮忙EventSink方面的问题 向listview1指定的位置写入字符串? 数据库表记录同步更新。 动态组键如何实现鼠标拖动? 预祝小HT生日快乐! 在Dll中动态生成Frame的问题,不解中......大侠们请帮一把 关于报表打印的问题,特急,请帮忙! 能否提供一个简单的三层结构的范例-- 高手请进!如何用独立的线程控制特定的窗体??? 新手 我开始学DELPHI 我现在是从数据库部分开始学 在局域网中,直到对方的ip地址,发送一个信息,适时接受并能弹出一个消息提示
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, StdCtrls;
const
MY_MESSAGE = wm_user+100;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
procedure OnIconNotify(var Message: TMessage);message MY_MESSAGE; public
{ Public declarations }
end;var
Form1: TForm1;
procedure AddSystray(hnd:HWnd);
procedure DelSystray(hnd:HWnd);
implementation{$R *.dfm}
procedure AddSystray(hnd:HWnd);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.Wnd := hnd; // 主窗口句柄
nid.uID := 11; // 内部标识,可设为任意数
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('Add systray Failed!');
end;
end;procedure DelSystray(hnd:HWnd);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.uID := 11; //内部标识,与加入小图标时的数一致
nid.Wnd := hnd; //主窗口句柄
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
end;{ TForm1 }procedure TForm1.OnIconNotify(var Message: TMessage);
var
Busy: Boolean;
begin
Busy:=False;
if not Busy then
begin
Busy := true;
if Message.LParam=WM_LBUTTONDOWN then
begin
if Application.MessageBox('Are you sure','Exit', MB_YESNO)=IDYES then
show;
end;
end;
Busy := false;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
AddSystray(handle);
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DelSystray(handle);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
hide;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ShellAPI, StdCtrls, Menus;
const WM_NID=WM_USER+1000;
type
TForm2 = class(TForm)
PopupMenu1: TPopupMenu;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
NotifyIcon:TNotifyIconData;
procedure WMNID(var msg:TMessage);message WM_NID;
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}procedure TForm2.FormCreate(Sender: TObject);
Begin
//NotifyIcon为全局变量,在程序的开头已经定义了
with NotifyIcon do
begin
cbSize:=SizeOf(TNotifyIconData);
Wnd:=Handle; //指向当前窗体Form1的句柄
uID:=1;
uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage:=WM_NID;
hIcon:=Application.Icon.Handle;
szTip:='张家恶少';
end;
//把设置好的变量NotifyIcon加入到系统中以便处理
Shell_NotifyIcon(NIM_ADD,@NotifyIcon);End;
procedure tform2.WMNID(var msg:TMessage);
begin
case msg.LParam of
WM_LBUTTONUp:Form2.Visible:=not Form2.Visible;
//WM_RBUTTONUP: ShowMessage('您点击的是右键');
WM_RBUTTONUP:
begin
PopupMenu1.Popup(mouse.CursorPos.X,mouse.CursorPos.Y);
end;
End;
End;
end.
原来我用系统API作,但结果却不如用RxTrayIcon感觉效果好
而且它也有例子,很快就可以搞定