📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,ShellApi;
const
MY_MESSAGE = WM_USER + 100;
type
TfrmMain = class(TForm)
PopupMenu1: TPopupMenu;
mnuIcon: TMenuItem;
procedure mnuIconClick(Sender: TObject);
private
{ Private declarations }
procedure IconOnClick(var message:TMessage); message MY_MESSAGE;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
NT:TNOTIFYICONDATA;
implementation
{$R *.dfm}
procedure TfrmMain.IconOnClick( var message: Tmessage);
var
p : TPoint;
begin
if (message.lParam = WM_LBUTTONDOWN) then
;
if (message.lParam = WM_RBUTTONDOWN) then
begin
GetCursorPos(p);
self.PopupMenu1.Popup( p.x ,p.y );
end;
end;
procedure TfrmMain.mnuIconClick(Sender: TObject);
begin
if Pos('缩为小图标',self.mnuIcon.Caption)>0 then
begin
with NT do begin
cbSize:=Sizeof(NT);
// nid变量的字节数
Wnd:=Handle;
// 主窗口句柄
UID:=0;
// 内部标识,可设为任意数
uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallBackMessage:=MY_MESSAGE;
hIcon:=Icon.Handle;
// 要加入的图标句柄,可任意指定
szTip:='Delphi'#0;
// 提示字符串
hIcon := Application.Icon.Handle;
end;
Application.Minimize;
ShowWindow(Application.Handle,SW_HIDE);
Shell_NotifyIcon(NIM_ADD,@NT);
self.mnuIcon.Caption:='正常显示';
end
else
begin
Shell_NotifyIcon(NIM_DELETE,@NT);
ShowWindow(Application.Handle,SW_SHOW);
Application.Restore;
self.mnuIcon.Caption:='缩为小图标';
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -