delphi 关闭时缩小到托盘_delphi trayIcon控件,如何实现窗口最小化的时候到系统托盘?...

该博客介绍了如何在Delphi应用程序中实现窗口最小化时隐藏到系统托盘,并通过右键菜单重新打开。作者通过Shell_NotifyIcon函数添加和修改通知图标,设置WM_TRAYNOTIFY消息处理程序来响应用户的操作,如双击恢复窗口和右键菜单选项。此外,还展示了如何在按钮点击事件中触发这些功能。
ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

trayIcon控件,如何实现窗口最小化的时候到系统托盘?

就象QQ的那样,一点最小化就到右下脚的图标里,点击右下脚图标,又能打开窗体。

应该如何设置属性,或者事件呢?拜托各位大哥……指教一二

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls,shellapi, Menus, ExtCtrls;

const

WM_TRAYNOTIFY=10;

type

TForm1 = class(TForm)

Button1: TButton;

PopupMenu1: TPopupMenu;

N1: TMenuItem;

N2: TMenuItem;

Timer1: TTimer;

Button2: TButton;

Button3: TButton;

procedure FormCreate(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure wmTrayNotify(var Msg:TMessage);message WM_TRAYNOTIFY;

procedure N1Click(Sender: TObject);

procedure N2Click(Sender: TObject);

procedure FormShow(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure Timer1Timer(Sender: TObject);

procedure Button3Click(Sender: TObject);

private

ChangeFlag: Boolean;

A:Boolean;

Icon: TIcon;

Nid:TNotifyIconData;

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);

begin

ChangeFlag := false;

A:= True;

{ Nid.cbSize:=sizeof(TNotifyIconData);

Nid.Wnd:=Handle;

Nid.uID:=1000;

Nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;

Nid.uCallbackMessage:=WM_TRAYNOTIFY;

Nid.hIcon:=Application.Icon.Handle;

Nid.szTip:='我隐藏在系统托盘里了';

Shell_NotifyIcon(NIM_ADD,@Nid); }

Icon:= TIcon.Create;

Icon.LoadFromFile('C:\Program Files\Microsoft Office\OFFICE11\MSN.ICO');

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

Shell_NotifyIcon(NIM_DELETE,@Nid);

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

Nid.cbSize:=sizeof(TNotifyIconData);

Nid.Wnd:=Handle;

Nid.uID:=1000;

Nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;

Nid.uCallbackMessage:=WM_TRAYNOTIFY;

Nid.hIcon:=Application.Icon.Handle;

Nid.szTip:='我隐藏在系统托盘里了';

Shell_NotifyIcon(NIM_ADD,@Nid);

ShowWindow(Application.Handle,SW_SHOWMINIMIZED);

ShowWindow(Application.Handle,SW_HIDE);

Timer1.Enabled:= True;

end;

procedure TForm1.wmTrayNotify(var Msg: TMessage);

var

p:TPoint;

begin

if(Msg.lparam=WM_LBUTTONDBLCLK) then

begin

ShowWindow(Application.Handle,SW_SHOW);

Shell_NotifyIcon(NIM_DELETE,@Nid);

Timer1.Enabled:= False;

Application.Restore;

end

else if(Msg.LParam=WM_RButtonUp) then

begin

GetCursorPos(P);//获得鼠标坐标

PopupMenu1.Popup(P.X, P.Y);//在鼠标光标处显示弹出菜单

end;

end;

procedure TForm1.N1Click(Sender: TObject);

begin

ShowWindow(Application.Handle,SW_SHOW);

Shell_NotifyIcon(NIM_DELETE,@Nid);

Application.Restore;

Timer1.Enabled:= False;

end;

procedure TForm1.N2Click(Sender: TObject);

begin

Application.Terminate;

end;

procedure TForm1.FormShow(Sender: TObject);

begin

Timer1.Enabled:= False;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

ChangeFlag:= True;

{ Icon:= TIcon.Create;

Icon.LoadFromFile('C:\Program Files\Microsoft Office\OFFICE11\MSN.ICO');

Nid.cbSize:=sizeof(TNotifyIconData);

Nid.Wnd:=Handle;

Nid.uID:=1000;

Nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;

Nid.uCallbackMessage:=WM_TRAYNOTIFY;

Nid.hIcon:=Icon.Handle;

Shell_NotifyIcon(NIM_MODIFY,@Nid);}

end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin

if not ChangeFlag then

Exit;

if A then

begin

Nid.hIcon:= Icon.Handle;

Shell_NotifyIcon(NIM_MODIFY,@Nid);

A:= False;

end

else begin

Nid.hIcon:= Application.Icon.Handle;

Shell_NotifyIcon(NIM_MODIFY,@Nid);

A:= True;

end;

end;

procedure TForm1.Button3Click(Sender: TObject);

begin

ChangeFlag:= False;

end;

end.

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值