123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- unit AnimateWinService;
- interface
- uses ShellAPI, Menus, Controls, Messages, Types, Windows, Forms;
- const
- WM_TrayIcon = WM_USER + 1001;
- type
- TAnimateWinService = class
- private
- FWinControl: TWinControl;
- FIconData: TNotifyIconData;
- public
- procedure AddIconToTray;
- procedure DelIconFromTray;
- procedure MinAnimate;
- property WinControl: TWinControl read FWinControl write FWinControl;
- end;
- implementation
- { TAnimateWinService }
- procedure TAnimateWinService.AddIconToTray;
- begin
- ZeroMemory(@FIconData, SizeOf(TNotifyIconData));
- FIconData.cbSize := SizeOf(TNotifyIconData);
- FIconData.Wnd := FWinControl.Handle;
- FIconData.uID := 1;
- FIconData.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
- FIconData.uCallbackMessage := WM_TrayIcon;
- FIconData.hIcon := Application.Icon.Handle;
- FIconData.szTip := 'Smartcost·þÎñÆ÷';
- Shell_NotifyIcon(NIM_ADD, @FIconData);
- end;
- procedure TAnimateWinService.DelIconFromTray;
- begin
- Shell_NotifyIcon(NIM_DELETE, @FIconData);
- end;
- procedure TAnimateWinService.MinAnimate;
- var
- RcStart: TRect;
- RcEnd: TRect;
- RcTray: TRect;
- HwndTray: hWnd;
- HwndChild: hWnd;
- begin
- HwndTray := FindWindow('Shell_TrayWnd', nil);
- HwndChild := FindWindowEx(hwndTray, 0, 'TrayNotifyWnd', nil);
- GetWindowRect(HwndChild, RcTray);
- RcStart := FWinControl.BoundsRect;
- RcEnd := RcTray;
- RcEnd.Left := RcEnd.Left + 5;
- RcEnd.Right := RcEnd.Left + 1;
- DrawAnimatedRects(FWinControl.Handle, IDANI_CAPTION or IDANI_CLOSE, RcStart, RcEnd);
- end;
- end.
|