SYSTRAY.C 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "main.h"
  2. #define SYSTRAY_ICON_BASE 1024
  3. int ist = 0;
  4. BOOL systray_isintray(void)
  5. {
  6. return ist;
  7. }
  8. void CopyCharW(wchar_t *dest, const wchar_t *src)
  9. {
  10. wchar_t *end = CharNextW(src);
  11. int count = (int)(end-src);
  12. while (count--)
  13. {
  14. *dest++=*src++;
  15. }
  16. }
  17. static void mktipstr(wchar_t *out, wchar_t *in, size_t outlen)
  18. {
  19. wchar_t *nextOut;
  20. size_t outpos=0;
  21. while (outpos < outlen-1 && *in)
  22. {
  23. if (*in == L'&')
  24. {
  25. if ((outpos+=2) >= outlen-1) break;
  26. *out++=L'&';
  27. *out++=L'&';
  28. }
  29. CopyCharW(out, in);
  30. nextOut = CharNextW(out);
  31. in = CharNextW(in);
  32. outpos+=(nextOut-out);
  33. out=nextOut;
  34. }
  35. *out=0;
  36. }
  37. BOOL systray_add(HWND hwnd, HICON hIcon, LPWSTR lpszTip)
  38. {
  39. NOTIFYICONDATAW tnid = {0};
  40. tnid.cbSize = sizeof(NOTIFYICONDATAW);
  41. tnid.hWnd = hwnd;
  42. tnid.uID = SYSTRAY_ICON_BASE;
  43. tnid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
  44. tnid.uCallbackMessage = WM_USER+8;
  45. tnid.hIcon = hIcon;
  46. mktipstr(tnid.szTip, lpszTip, sizeof(tnid.szTip)/sizeof(wchar_t));
  47. ist = 1;
  48. return Shell_NotifyIconW(NIM_ADD, &tnid);
  49. }
  50. BOOL systray_mod(HWND hwnd, HICON hIcon, LPWSTR lpszTip) {
  51. NOTIFYICONDATAW tnid = {0};
  52. tnid.cbSize = sizeof(NOTIFYICONDATAW);
  53. tnid.hWnd = hwnd;
  54. tnid.uID = SYSTRAY_ICON_BASE;
  55. tnid.hIcon = hIcon;
  56. tnid.uFlags = (lpszTip ? NIF_TIP : 0) | (hIcon ? NIF_ICON : 0);
  57. if (lpszTip) mktipstr(tnid.szTip, lpszTip, sizeof(tnid.szTip)/sizeof(wchar_t));
  58. return (Shell_NotifyIconW(NIM_MODIFY, &tnid));
  59. }
  60. BOOL systray_del(HWND hwnd) {
  61. NOTIFYICONDATAW tnid = {0};
  62. tnid.cbSize = sizeof(NOTIFYICONDATAW);
  63. tnid.hWnd = hwnd;
  64. tnid.uID = SYSTRAY_ICON_BASE;
  65. ist = 0;
  66. return(Shell_NotifyIconW(NIM_DELETE, &tnid));
  67. }