您的位置:首页 > 其它

一个简单的系统托盘程序

2010-12-28 11:22 507 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: