在工程文件的 Application.Initialize; 前面添上
Application.ShowMainForm := False;
然后。。。。。
unit Main;
interface
uses
Windows, Messages, SysUtils, Forms, ShellAPI, ComCtrls, ScktComp,
Gauges, ImgList, Classes, Menus;
const
WM_MIDASICON = WM_USER + 1;
type
TForm1 = class(TForm)
procedure FormDestroy(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
private
FIconData: TNotifyIconData;
protected
procedure WMMIDASIcon(var Message: TMessage); message WM_MIDASICON;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @FIconData);
end;
procedure TForm1.WMMIDASIcon(var Message: TMessage);
begin
case Message.LParam of
WM_RBUTTONUP: Application.Terminate ; //右键退出
WM_LBUTTONUP: begin //左键显示窗体
if NOT Visible then show;
SetForegroundWindow(Handle);
end;
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
CanClose:=False;
Application.Minimize ;
Hide ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with FIconData do
begin
cbSize := SizeOf(FIconData);
Wnd := Self.Handle;
uID := $DEDB;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
hIcon := Application.Icon.Handle;
uCallbackMessage := WM_MIDASICON;
StrCopy(szTip, PChar(Caption));
end;
Shell_NotifyIcon(NIM_Add, @FIconData);
end;
end.
嘻嘻。。。
(*^v^*)