一个简单的系统托盘程序

Delphi System Tray Application,版本高于D7时设置Application.ShowMainForm := False;在隐藏的时候,任务栏不显示。

 

代码
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, AppEvnts;
const
WM_ICONTRAY
= WM_USER + 100;
type
TForm1
= class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
TrayIconData: TNotifyIConData;
public
{ Public declarations }
procedure TrayMessage(var aMsg:TMessage);message WM_ICONTRAY;
end;
var
Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
with TrayIconData do
begin
cbSize :
= SizeOf(TrayIconData);
wnd :
= Self.Handle;
uID :
= 0;
uFlags :
= NIF_MESSAGE + NIF_ICON + NIF_TIP;
uCallbackMessage :
= WM_ICONTRAY;
hIcon :
= Application.Icon.Handle; //LoadIcon(HInstance,'newIcon'); 加载自己的Icon
StrPCopy(szTip,Application.Title);
end;
Shell_NotifyIcon(NIM_ADD,@TrayIconData);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@TrayICONData);
end;

procedure TForm1.TrayMessage(var aMsg: TMessage);
begin
case aMsg.LParam of
WM_LBUTTONDOWN:
begin
ShowMessage(
'Left button clicked - let''s SHOW the Form!');
Application.MainForm.Show;
end;
WM_RBUTTONDOWN:
begin
ShowMessage(
'Right button clicked - let''s HIDE the Form!');
Application.MainForm.Hide;
end;
end;
end;

end.

 

 

 

posted @ 2010-12-28 11:22  Jekhn  阅读(318)  评论(0编辑  收藏  举报