Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15530722
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类:

2010-01-27 13:20:52

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.
阅读(1572) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~