谁有托盘程序的例子代码? 象瑞星一样的,点击最小化就变成托盘,双击打开窗口,右键可以弹出菜单,然后可以关闭 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可到http://www.2ccc.com中去下載一個trayicon控件安裝好把它放到窗體上設置如下MinimizeToTray:=trueCycleicons:=trueIconVisible:=true在CoolTrayIcon1雙擊事件中寫入以下代碼:procedure TForm1.CoolTrayIcon1DblClick(Sender: TObject);begin Application.Restore;end; unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,shellapi, Menus, AppEvnts,Registry; const mousemsg = wm_user + 1; //自定义消息,用于处理用户在图标上点击鼠标的事件 iid = 100; //用户自定义数值,在TnotifyIconDataA类型全局变量ntida中使用type TForm1 = class(TForm) Button1: TButton; PopupMenu1: TPopupMenu; N1: TMenuItem; ApplicationEvents1: TApplicationEvents; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button1Click(Sender: TObject); procedure ApplicationEvents1Minimize(Sender: TObject); procedure FormShow(Sender: TObject); private procedure mousemessage(var message: tmessage); message mousemsg; { Private declarations } public { Public declarations } end;var Form1: TForm1; ntida:TNotifyIcondataA; //用于增加和删除系统状态图标 implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin ntida.cbSize := sizeof(tnotifyicondataa); //指定ntida的长度 ntida.Wnd := handle; //取应用程序主窗体的句柄 ntida.uID := iid; //用户自定义的一个数值,在uCallbackMessage参数指定的消息中使 ntida.uFlags := nif_icon + nif_tip + nif_message; //指定在该结构中uCallbackMessage、hIcon和szTip参数都有效 ntida.uCallbackMessage := mousemsg; //指定的窗口消息 // ntida.hIcon := Application.Icon.handle; //指定系统状态栏显示应用程序的图标句柄 ntida.szTip := 'Icon'; //当鼠标停留在系统状态栏该图标上时,出现该提示信息 shell_notifyicona(NIM_ADD, @ntida); //在系统状态栏增加一个新图标end;procedure TForm1.mousemessage(var message: tmessage);var mousept: TPoint; //鼠标点击位置begin inherited; if message.LParam = wm_rbuttonup then begin //用鼠标右键点击图标 getcursorpos(mousept); //获取光标位置 popupmenu1.popup(mousept.x, mousept.y); //在光标位置弹出选单 end; if message.LParam = wm_lbuttonup then begin //用鼠标左键点击图标 { //显示应用程序窗口 ShowWindow(Handle, SW_SHOW); //在任务栏上显示应用程序窗口 ShowWindow(Application.handle, SW_SHOW); SetWindowLong(Application.Handle, GWL_EXSTYLE, not (GetWindowLong(Application.handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW)); } end; message.Result := 0;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin Action := caNone; //不对窗体进行任何操作 ShowWindow(Handle, SW_HIDE); //隐藏主窗体 //隐藏应用程序窗口在任务栏上的显示 ShowWindow(Application.Handle, SW_HIDE); SetWindowLong(Application.Handle, GWL_EXSTYLE, not (GetWindowLong(Application.handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW));end;procedure TForm1.Button1Click(Sender: TObject);begin ntida.cbSize := sizeof(tnotifyicondataa); ntida.wnd := handle; ntida.uID := iid; ntida.uFlags := nif_icon + nif_tip + nif_message; ntida.uCallbackMessage := mousemsg; ntida.hIcon := Application.Icon.handle; ntida.szTip := 'Icon'; shell_notifyicona(NIM_DELETE, @ntida); //删除已有的应用程序图标 Application.Terminate; //中断应用程序运行,退出应用程序 end;end. 例子太多了,不过建议下载TrayIcon控件,确实很好用 to jackie168(三箭齐发)我把您提供的代码在delphi7中编译怎么通不过。消息如下:[Error] Unit1.pas(20): Unsatisfied forward or external declaration: 'TForm1.ApplicationEvents1Minimize'[Error] Unit1.pas(21): Unsatisfied forward or external declaration: 'TForm1.FormShow'[Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'另外:有些类似的托盘例子,可以把程序调通,但不会显示在托盘上,我的系统是win2000,这又是为什么?希望能给出答案,谢谢先!----------------------------------------unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,shellapi, Menus, AppEvnts,Registry; const mousemsg = wm_user + 1; //自定义消息,用于处理用户在图标上点击鼠标的事件 iid = 100; //用户自定义数值,在TnotifyIconDataA类型全局变量ntida中使用type TForm1 = class(TForm) Button1: TButton; PopupMenu1: TPopupMenu; N1: TMenuItem; ApplicationEvents1: TApplicationEvents; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button1Click(Sender: TObject); procedure ApplicationEvents1Minimize(Sender: TObject); procedure FormShow(Sender: TObject); private procedure mousemessage(var message: tmessage); message mousemsg; { Private declarations } public { Public declarations } end;var Form1: TForm1; ntida:TNotifyIcondataA; //用于增加和删除系统状态图标 implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin ntida.cbSize := sizeof(tnotifyicondataa); //指定ntida的长度 ntida.Wnd := handle; //取应用程序主窗体的句柄 ntida.uID := iid; //用户自定义的一个数值,在uCallbackMessage参数指定的消息中使 ntida.uFlags := nif_icon + nif_tip + nif_message; //指定在该结构中uCallbackMessage、hIcon和szTip参数都有效 ntida.uCallbackMessage := mousemsg; //指定的窗口消息 // ntida.hIcon := Application.Icon.handle; //指定系统状态栏显示应用程序的图标句柄 ntida.szTip := 'Icon'; //当鼠标停留在系统状态栏该图标上时,出现该提示信息 shell_notifyicona(NIM_ADD, @ntida); //在系统状态栏增加一个新图标end;procedure TForm1.mousemessage(var message: tmessage);var mousept: TPoint; //鼠标点击位置begin inherited; if message.LParam = wm_rbuttonup then begin //用鼠标右键点击图标 getcursorpos(mousept); //获取光标位置 popupmenu1.popup(mousept.x, mousept.y); //在光标位置弹出选单 end; if message.LParam = wm_lbuttonup then begin //用鼠标左键点击图标 { //显示应用程序窗口 ShowWindow(Handle, SW_SHOW); //在任务栏上显示应用程序窗口 ShowWindow(Application.handle, SW_SHOW); SetWindowLong(Application.Handle, GWL_EXSTYLE, not (GetWindowLong(Application.handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW)); } end; message.Result := 0;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin Action := caNone; //不对窗体进行任何操作 ShowWindow(Handle, SW_HIDE); //隐藏主窗体 //隐藏应用程序窗口在任务栏上的显示 ShowWindow(Application.Handle, SW_HIDE); SetWindowLong(Application.Handle, GWL_EXSTYLE, not (GetWindowLong(Application.handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW));end;procedure TForm1.Button1Click(Sender: TObject);begin ntida.cbSize := sizeof(tnotifyicondataa); ntida.wnd := handle; ntida.uID := iid; ntida.uFlags := nif_icon + nif_tip + nif_message; ntida.uCallbackMessage := mousemsg; ntida.hIcon := Application.Icon.handle; ntida.szTip := 'Icon'; shell_notifyicona(NIM_DELETE, @ntida); //删除已有的应用程序图标 Application.Terminate; //中断应用程序运行,退出应用程序 end;end. 运行可执行文件,如flashget出现异常时,他自动调用delphi进行调试,请问如何设置,不让调用调试程序? 可以通过一个程序取得另一个程序grid中的文字??? 建议开一个关于Delphi组件开发的栏目! 如何获取指定数据表中所有字段???? 问个简单问题:Delphi中续行符是什么? 问一个客户端与数据库的同步更新问题 非常简单的题目,谁都会,快来吧 来者有分 请教一个问题 大家看看我的问题!!! 目录操作的一个简单问题 好难的DELPHI+SQL问题?? 文字特效问题,紧急求助
設置如下
MinimizeToTray:=true
Cycleicons:=true
IconVisible:=true在CoolTrayIcon1雙擊事件中寫入以下代碼:
procedure TForm1.CoolTrayIcon1DblClick(Sender: TObject);
begin
Application.Restore;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi, Menus, AppEvnts,Registry;
const
mousemsg = wm_user + 1; //自定义消息,用于处理用户在图标上点击鼠标的事件
iid = 100; //用户自定义数值,在TnotifyIconDataA类型全局变量ntida中使用
type
TForm1 = class(TForm)
Button1: TButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure ApplicationEvents1Minimize(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure mousemessage(var message: tmessage); message mousemsg;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
ntida:TNotifyIcondataA; //用于增加和删除系统状态图标
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
ntida.cbSize := sizeof(tnotifyicondataa); //指定ntida的长度
ntida.Wnd := handle; //取应用程序主窗体的句柄
ntida.uID := iid; //用户自定义的一个数值,在uCallbackMessage参数指定的消息中使
ntida.uFlags := nif_icon + nif_tip +
nif_message; //指定在该结构中uCallbackMessage、hIcon和szTip参数都有效
ntida.uCallbackMessage := mousemsg;
//指定的窗口消息
// ntida.hIcon := Application.Icon.handle;
//指定系统状态栏显示应用程序的图标句柄
ntida.szTip := 'Icon';
//当鼠标停留在系统状态栏该图标上时,出现该提示信息
shell_notifyicona(NIM_ADD, @ntida);
//在系统状态栏增加一个新图标
end;
procedure TForm1.mousemessage(var message: tmessage);
var
mousept: TPoint; //鼠标点击位置
begin
inherited;
if message.LParam = wm_rbuttonup then begin //用鼠标右键点击图标
getcursorpos(mousept); //获取光标位置
popupmenu1.popup(mousept.x, mousept.y);
//在光标位置弹出选单
end;
if message.LParam = wm_lbuttonup then begin //用鼠标左键点击图标
{ //显示应用程序窗口
ShowWindow(Handle, SW_SHOW);
//在任务栏上显示应用程序窗口
ShowWindow(Application.handle, SW_SHOW);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW)); }
end;
message.Result := 0;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone; //不对窗体进行任何操作
ShowWindow(Handle, SW_HIDE); //隐藏主窗体
//隐藏应用程序窗口在任务栏上的显示
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW));
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ntida.cbSize := sizeof(tnotifyicondataa);
ntida.wnd := handle;
ntida.uID := iid;
ntida.uFlags := nif_icon + nif_tip + nif_message;
ntida.uCallbackMessage := mousemsg;
ntida.hIcon := Application.Icon.handle;
ntida.szTip := 'Icon';
shell_notifyicona(NIM_DELETE, @ntida);
//删除已有的应用程序图标
Application.Terminate;
//中断应用程序运行,退出应用程序
end;end.
我把您提供的代码在delphi7中编译怎么通不过。
消息如下:
[Error] Unit1.pas(20): Unsatisfied forward or external declaration: 'TForm1.ApplicationEvents1Minimize'[Error] Unit1.pas(21): Unsatisfied forward or external declaration: 'TForm1.FormShow'[Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'另外:有些类似的托盘例子,可以把程序调通,但不会显示在托盘上,我的系统是win2000,这又是为什么?
希望能给出答案,谢谢先!
----------------------------------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi, Menus, AppEvnts,Registry;
const
mousemsg = wm_user + 1; //自定义消息,用于处理用户在图标上点击鼠标的事件
iid = 100; //用户自定义数值,在TnotifyIconDataA类型全局变量ntida中使用
type
TForm1 = class(TForm)
Button1: TButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure ApplicationEvents1Minimize(Sender: TObject);
procedure FormShow(Sender: TObject);
private
procedure mousemessage(var message: tmessage); message mousemsg;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
ntida:TNotifyIcondataA; //用于增加和删除系统状态图标
implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
ntida.cbSize := sizeof(tnotifyicondataa); //指定ntida的长度
ntida.Wnd := handle; //取应用程序主窗体的句柄
ntida.uID := iid; //用户自定义的一个数值,在uCallbackMessage参数指定的消息中使
ntida.uFlags := nif_icon + nif_tip +
nif_message; //指定在该结构中uCallbackMessage、hIcon和szTip参数都有效
ntida.uCallbackMessage := mousemsg;
//指定的窗口消息
// ntida.hIcon := Application.Icon.handle;
//指定系统状态栏显示应用程序的图标句柄
ntida.szTip := 'Icon';
//当鼠标停留在系统状态栏该图标上时,出现该提示信息
shell_notifyicona(NIM_ADD, @ntida);
//在系统状态栏增加一个新图标
end;
procedure TForm1.mousemessage(var message: tmessage);
var
mousept: TPoint; //鼠标点击位置
begin
inherited;
if message.LParam = wm_rbuttonup then begin //用鼠标右键点击图标
getcursorpos(mousept); //获取光标位置
popupmenu1.popup(mousept.x, mousept.y);
//在光标位置弹出选单
end;
if message.LParam = wm_lbuttonup then begin //用鼠标左键点击图标
{ //显示应用程序窗口
ShowWindow(Handle, SW_SHOW);
//在任务栏上显示应用程序窗口
ShowWindow(Application.handle, SW_SHOW);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW)); }
end;
message.Result := 0;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone; //不对窗体进行任何操作
ShowWindow(Handle, SW_HIDE); //隐藏主窗体
//隐藏应用程序窗口在任务栏上的显示
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
not (GetWindowLong(Application.handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW));
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ntida.cbSize := sizeof(tnotifyicondataa);
ntida.wnd := handle;
ntida.uID := iid;
ntida.uFlags := nif_icon + nif_tip + nif_message;
ntida.uCallbackMessage := mousemsg;
ntida.hIcon := Application.Icon.handle;
ntida.szTip := 'Icon';
shell_notifyicona(NIM_DELETE, @ntida);
//删除已有的应用程序图标
Application.Terminate;
//中断应用程序运行,退出应用程序
end;end.