procedure TTrayIcon.DelTrayIcon;
begin
Shell_NotifyIcon(NIM_DELETE, @IconData);
end;
destructor TTrayIcon.Destroy;
begin
Visible := False;
Classes.DeallocateHWnd(FHandle);
inherited;
end;
procedure TTrayIcon.SetTrayIcon;
begin
IconData.hIcon := Application.Icon.Handle;
StrLCopy(IconData.szTip, PChar(Application.Title), SizeOf(IconData.szTip)-1);
IconData.szTip[SizeOf(IconData.szTip)-1] := #0;
end;
procedure TTrayIcon.Loaded;
begin
inherited Loaded;
if csDesigning in ComponentState then Exit;
if FVisible then AddTrayIcon;
end;
procedure TTrayIcon.SetVisible(const Value: Boolean);
begin
if Value <> FVisible then
begin
FVisible := Value;
if csDesigning in ComponentState then Exit;
if Value then AddTrayIcon else DelTrayIcon;
end;
end;
procedure TTrayIcon.WndProc(var Message: TMessage);
begin
with Message do
if Msg = WM_TRAYICONEVENT then
try
case LParam of
WM_LBUTTONUP:
if Assigned(FOnClick) then FOnClick(Self);
WM_RBUTTONUP:
if Assigned(FOnRightClick) then FOnRightClick(Self);
end;
except
Application.HandleException(Self);
end
else Result := DefWindowProc(FHandle, Msg, WParam, LParam);
end;
end.
上一页 [1] [2]
责任编辑:小草