delphi托盘效果实例-Delphi-优质IT资源分享社区

admin
管理员
管理员
  • UID1
  • 粉丝26
  • 关注4
  • 发帖数581
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:151回复:0

delphi托盘效果实例

楼主#
更多 发布于:2016-06-13 13:42

unit Unit1;
interface
uses
揭穿装机内部秘密 七大细节帮你解读用U盘装置Win8双体系图文教程
以不变应万变 风景拍摄摄影窍门集锦重装Win 7 五项不得不做的初始设置
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, ShellAPI, AppEvnts, StdCtrls, Menus;
const WM_NID = WM_User + 1000;
离别灰蒙蒙 菜鸟必读曝光补偿运用窍门win8怎样关机?教你4种win8关机办法
不必整形也上镜 教你怎么变成“锥子脸”Win7体系不一样的小功用汇总
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
Label1: TLabel;
pm1: TPopupMenu;
mniN3: TMenuItem;
mniN4: TMenuItem;
procedure FormDestroy(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure mniN3Click(Sender: TObject);
procedure mniN4Click(Sender: TObject);
private
{ Private declarations }
procedure SysCommand(var SysMsg: TMessage); message WM_SYSCOMMAND;
procedure WMNID(var msg:TMessage); message WM_NID;
public
{ Public declarations }
end;
var
Form1: TForm1;
NotifyIcon: TNotifyIconData;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.SysCommand(var SysMsg: TMessage);
begin
case SysMsg.WParam of
SC_MINIMIZE: // 当最小化时
begin
SetWindowPos(Application.Handle, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_HIDEWINDOW);
Hide; // 在
任务栏
潜藏程序
// 在托盘区显现图标
with NotifyIcon do
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Handle;
uID := 1;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage := WM_NID;
hIcon := Application.Icon.Handle;
szTip := '托盘程序';
end;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon); // 在托盘区显现图标
end;
else
inherited;
end;
end;
procedure TForm1.WMNID(var msg: TMessage);
var
mousepos: TPoint;
begin
GetCursorPos(mousepos); //获取鼠标方位
case msg.LParam of
WM_LBUTTONUP: // 在托盘区点击左键后
begin
Form1.Visible := not Form1.Visible; // 显现主窗体与否
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 显现主窗体后删去托盘区的图标
SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);
//

任务栏显现程序
end;
WM_RBUTTONUP: PopupMenu1.Popup(mousepos.X, mousepos.Y); // 弹出菜单
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 删去托盘图标
end;
procedure TForm1.N1Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
Form1.Visible := true; // 显现窗体
SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 删去托盘图标
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AnimateWindow(Handle,1000,AW_CENTER);//窗口由小变大
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AnimateWindow (Handle, 400, AW_HIDE or AW_BLEND);//窗口
仓促消逝
end;
procedure TForm1.mniN3Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.mniN4Click(Sender: TObject);
begin
shellexecute(handle,'open','http://www.aheasy.cn',nil,nil,SW_show);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, ShellAPI, AppEvnts, StdCtrls, Menus;
const WM_NID = WM_User + 1000;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
Label1: TLabel;
pm1: TPopupMenu;
mniN3: TMenuItem;
mniN4: TMenuItem;
procedure FormDestroy(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure mniN3Click(Sender: TObject);
procedure mniN4Click(Sender: TObject);
private
{ Private declarations }
procedure SysCommand(var SysMsg: TMessage); message WM_SYSCOMMAND;
procedure WMNID(var msg:TMessage); message WM_NID;
public
{ Public declarations }
end;
var
Form1: TForm1;
NotifyIcon: TNotifyIconData;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.SysCommand(var SysMsg: TMessage);
begin
case SysMsg.WParam of
SC_MINIMIZE: // 当最小化时
begin
SetWindowPos(Application.Handle, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_HIDEWINDOW);
Hide; // 在
任务栏
潜藏程序
// 在托盘区显现图标
with NotifyIcon do
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Handle;
uID := 1;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage := WM_NID;
hIcon := Application.Icon.Handle;
szTip := '托盘程序';
end;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon); // 在托盘区显现图标
end;
else
inherited;
end;
end;
procedure TForm1.WMNID(var msg: TMessage);
var
mousepos: TPoint;
begin
GetCursorPos(mousepos); //获取鼠标方位
case msg.LParam of
WM_LBUTTONUP: // 在托盘区点击左键后
begin
Form1.Visible := not Form1.Visible; // 显现主窗体与否
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 显现主窗体后删去托盘区的图标
SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);
//

任务栏显现程序
end;
WM_RBUTTONUP: PopupMenu1.Popup(mousepos.X, mousepos.Y); // 弹出菜单
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 删去托盘图标
end;
procedure TForm1.N1Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
Form1.Visible := true; // 显现窗体
SetWindowPos(Application.Handle, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon); // 删去托盘图标
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AnimateWindow(Handle,1000,AW_CENTER);//窗口由小变大
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
AnimateWindow (Handle, 400, AW_HIDE or AW_BLEND);//窗口
仓促消逝
end;
procedure TForm1.mniN3Click(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.mniN4Click(Sender: TObject);
begin
shellexecute(handle,'open','http://www.aheasy.cn',nil,nil,SW_show);
end;
end.









优质IT资源分享社区为你提供此文。
本站有大量优质Delphi教程视频,资料等资源,包含Delphi基础教程,高级进阶教程等等,教程视频资源涵盖传智播客,极客学院,达内,北大青鸟,猎豹网校等等IT职业培训机构的培训教学视频,价值巨大。欢迎点击下方链接查看。
Delphi教程视频
优质IT资源分享社区(www.itziyuan.top)
一个免费,自由,开放,共享,平等,互助的优质IT资源分享网站。
专注免费分享各大IT培训机构最新培训教学视频,为你的IT学习助力!

!!!回帖受限制请看点击这里!!!
!!!资源失效请在此版块发帖说明!!!

[PS:按 CTRL+D收藏本站网址~]

——“优质IT资源分享社区”管理员专用签名~

本版相似帖子

游客