delphi系统托盘tray - delphi - gliethttp
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellAPI, Menus;
const
WM_TRAYNOTIFY = 3000;
type
TForm1 = class(TForm)
Button1: TButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
procedure Button1Click(Sender: TObject);
private
MINIFTPFF: TNotifyIconData;
MsgTaskbarRestart: Cardinal;
{ Private declarations }
public
procedure WndProc(var Msg: TMessage); override;
procedure MiniToTaskbar; //最小化到托盘
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.MiniToTaskbar;
begin
MsgTaskbarRestart := RegisterWindowMessage('TaskbarCreated');
ShowWindow(Application.Handle, SW_SHOWMINIMIZED);
ShowWindow(Application.Handle, SW_HIDE);
MINIFTPFF.cbSize := SizeOf(TNotifyIconData);
MINIFTPFF.Wnd := Handle;
MINIFTPFF.uID := 1985629;
MINIFTPFF.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
MINIFTPFF.uCallbackMessage := WM_TRAYNOTIFY;
MINIFTPFF.hIcon := Application.Icon.Handle;
MINIFTPFF.szTip := '这是个测试程序';
Shell_NotifyIcon(NIM_ADD, @MINIFTPFF);
end;
procedure TForm1.WndProc(var Msg: TMessage);
var
mouse:TPoint;
begin
inherited;
if Msg.LParam = WM_LBUTTONDBLCLK then
begin //双击图片图标还原窗体
ShowWindow(Application.Handle, SW_SHOW);
ShowWindow(Application.Handle, SW_SHOWNORMAL);
Application.BringToFront;
Shell_NotifyIcon(NIM_Delete, @MINIFTPFF);
end
else if Msg.LParam = WM_RBUTTONUP then
begin
SetForegroundWindow(Handle);
GetCursorPos(mouse);//获得鼠标坐标
PopupMenu1.Popup(mouse.X, mouse.Y);//在鼠标光标处显示弹出菜单
end;
// if (Msg.Msg = WM_NCACTIVATE) then
// PopupForm.Destroy;
// 响应任务栏托盘重建消息
if Msg.Msg = MsgTaskbarRestart then
MiniToTaskbar; // 最小化到托盘
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MiniToTaskbar;
end;
end.
郑重声明:资讯 【delphi系统托盘tray - delphi - gliethttp】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【
在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——