AnimateWinService.pas 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. unit AnimateWinService;
  2. interface
  3. uses ShellAPI, Menus, Controls, Messages, Types, Windows, Forms;
  4. const
  5. WM_TrayIcon = WM_USER + 1001;
  6. type
  7. TAnimateWinService = class
  8. private
  9. FWinControl: TWinControl;
  10. FIconData: TNotifyIconData;
  11. public
  12. procedure AddIconToTray;
  13. procedure DelIconFromTray;
  14. procedure MinAnimate;
  15. property WinControl: TWinControl read FWinControl write FWinControl;
  16. end;
  17. implementation
  18. { TAnimateWinService }
  19. procedure TAnimateWinService.AddIconToTray;
  20. begin
  21. ZeroMemory(@FIconData, SizeOf(TNotifyIconData));
  22. FIconData.cbSize := SizeOf(TNotifyIconData);
  23. FIconData.Wnd := FWinControl.Handle;
  24. FIconData.uID := 1;
  25. FIconData.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
  26. FIconData.uCallbackMessage := WM_TrayIcon;
  27. FIconData.hIcon := Application.Icon.Handle;
  28. FIconData.szTip := 'Smartcost·þÎñÆ÷';
  29. Shell_NotifyIcon(NIM_ADD, @FIconData);
  30. end;
  31. procedure TAnimateWinService.DelIconFromTray;
  32. begin
  33. Shell_NotifyIcon(NIM_DELETE, @FIconData);
  34. end;
  35. procedure TAnimateWinService.MinAnimate;
  36. var
  37. RcStart: TRect;
  38. RcEnd: TRect;
  39. RcTray: TRect;
  40. HwndTray: hWnd;
  41. HwndChild: hWnd;
  42. begin
  43. HwndTray := FindWindow('Shell_TrayWnd', nil);
  44. HwndChild := FindWindowEx(hwndTray, 0, 'TrayNotifyWnd', nil);
  45. GetWindowRect(HwndChild, RcTray);
  46. RcStart := FWinControl.BoundsRect;
  47. RcEnd := RcTray;
  48. RcEnd.Left := RcEnd.Left + 5;
  49. RcEnd.Right := RcEnd.Left + 1;
  50. DrawAnimatedRects(FWinControl.Handle, IDANI_CAPTION or IDANI_CLOSE, RcStart, RcEnd);
  51. end;
  52. end.