function CreateIconFromBmp(Bmp: TBitmap): TIcon;
//aus der DP ;)
begin
with TImageList.CreateSize(Bmp.Width, Bmp.Height)
do
try
{$IFDEF VER90}
with Bmp
do AddMasked(Bmp, Canvas.Pixels[Width-1, Height-1]);
{$ELSE}
AddMasked(Bmp, Bmp.TransparentColor);
{$ENDIF}
Result := TIcon.Create;
GetIcon(0, Result);
finally
Free;
end;
end;
procedure TForm1.IconTmrTimer(Sender: TObject);
var
I,J: Integer;
begin
Image1.Picture.Bitmap.Canvas.Brush.Color := clblue;
Image1.Picture.Bitmap.Canvas.FillRect(rect(0,0,16,16));
for I := 0
to 5
do
begin
for J := 0
to 3
do
begin
if ClockForm.BinLights[I].Lights[J] = True
then
begin
Image1.Picture.Bitmap.Canvas.Pixels[I*2+1,J*2+1] := clLime;
end;
end;
end;
TmpIcon.Free;
TmpIcon := CreateIconFromBmp(Image1.Picture.Bitmap);
TmpIcon.SaveToFile('
tmpIcon.ico');
//Öffnen mit anderen Programmen klappt ohne Probleme
Fillchar(NotifyIconData,Sizeof(NotifyIconData),0);
//dieser Abschnitt wird auch schon im OnCreate aufgerufen. Danach bleibt das Icon im Tray transparent
NotifyIconData.cbSize := Sizeof(NotifyIconData);
NotifyIconData.Wnd :=
Handle;
NotifyIconData.uFlags := NIF_MESSAGE
or NIF_ICON
or NIF_TIP;
NotifyIconData.uCallbackMessage := WM_TASKABAREVENT;
//NotifyIconData.hIcon := Application.Icon.Handle;
NotifyIconData.hIcon := TmpIcon.Handle;
NotifyIconData.szTip := '
BinaryClock';
Shell_NotifyIcon(NIM_ADD, @NotifyIconData);
end;