怎样将应用程序最小化后放到 SYSTEM TRAY 中(5分)

  • 主题发起人 主题发起人 protossgffnxk
  • 开始时间 开始时间
P

protossgffnxk

Unregistered / Unconfirmed
GUEST, unregistred user!
如MSN点击关闭或最小化后将程序放至系统托盘区
 
用TTrayIcon控件,网上很多
 
unit TrayIcon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus,shellapi;
type
//----------------------------------------------------------------------
PNotifyIconData = ^TNotifyIconDataA;
TNotifyIconDataA = record
cbSize : DWORD;
Wnd : HWND;
uID : UINT;
uFlags : UINT;
uCallbackMessage : UINT;
hIcon : HICON;
szTip : array [0..63] of AnsiChar;
end;
//----------------------------------------------------------------------
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
open1: TMenuItem;
close1: TMenuItem;
N1: TMenuItem;
about1: TMenuItem;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure open1Click(Sender: TObject);
procedure close1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
//-------------------------------------------------------------
IconData: TNotifyIconData;
procedure ShowIcon;
procedure IconOnClick(var message:TMessage);
message WM_USER+1;
Procedure WMSysCommand(Var message : TMessage) ;
Message WM_SYSCOMMAND ;
//-------------------------------------------------------------
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.IconOnClick( var message: Tmessage);
var p : TPoint;
begin
if (message.lParam = WM_LBUTTONDOWN) then
begin
ShowWindow(Handle, SW_SHOW );
end;

if (message.lParam = WM_RBUTTONDOWN) then
begin
GetCursorPos(p);
SetForegroundWindow (Application.Handle);
//<-------------------avoid a little bug.
Application.ProcessMessages;
popupmenu1.Popup( p.x ,p.y );
end;
end;

Procedure TForm1.WMSysCommand(Var Message : TMessage) ;
begin

if (Message.WParam = SC_MINIMIZE) then
begin
ShowIcon;
end
else
Inherited;
end;

procedure TForm1.ShowIcon;
begin
IconData.cbSize := SizeOf( IconData );
IconData.Wnd := Handle;
IconData.uID := 1;
IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
IconData.uCallBackMessage := WM_USER+1;
IconData.hIcon := application.Icon.Handle;
IconData.szTip := 'LANChat';
Shell_NotifyIcon( NIM_ADD, @IconData );
ShowWindow(Handle, SW_HIDE);
hide;
end;

procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Shell_NotifyIcon( NIM_DELETE, @IconData );
end;

procedure TForm1.open1Click(Sender: TObject);
begin
Form1.Show;
end;

procedure TForm1.close1Click(Sender: TObject);
begin
Form1.close;
end;

procedure TForm1.FormShow(Sender: TObject);
begin

showwindow(application.handle,sw_hide);

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
showicon;
end;

end.
 
THANKS zw84611
 
后退
顶部