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.
阅读(1557) | 评论(0) | 转发(0) |