TNotifyIconData在程序启动的有关问题
TNotifyIconData在程序启动的问题
//以下单元为什么在启动的时候不能最小化到托盘,而在按Button1事件的时候可以
unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellApi;
const
WM_NID = WM_USER + 100;
type
TForm5 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
var
NotifyIcon: TNotifyIconData;
procedure TForm5.Button1Click(Sender: TObject);
begin
with NotifyIcon do
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Handle;
uID := 1;
uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
uCallBackMessage := WM_NID;
hIcon := Application.Icon.Handle;
szTip := '临时测试程序 ';
end;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
Form5.Visible := False;
end;
procedure TForm5.FormCreate(Sender: TObject);
begin
Button1.Click;
end;
procedure TForm5.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon);
end;
end.
------解决方案--------------------
procedure TForm5.FormPaint(Sender: TObject);
begin
Button1.Click;
end;
//以下单元为什么在启动的时候不能最小化到托盘,而在按Button1事件的时候可以
unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellApi;
const
WM_NID = WM_USER + 100;
type
TForm5 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
var
NotifyIcon: TNotifyIconData;
procedure TForm5.Button1Click(Sender: TObject);
begin
with NotifyIcon do
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Handle;
uID := 1;
uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
uCallBackMessage := WM_NID;
hIcon := Application.Icon.Handle;
szTip := '临时测试程序 ';
end;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
Form5.Visible := False;
end;
procedure TForm5.FormCreate(Sender: TObject);
begin
Button1.Click;
end;
procedure TForm5.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon);
end;
end.
------解决方案--------------------
procedure TForm5.FormPaint(Sender: TObject);
begin
Button1.Click;
end;