Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.0 KiB

  1. //---------------------------------------------------------------------------
  2. //---------------------------------------------------------------------------
  3. #include "pch.h"
  4. #include "traynoti.h"
  5. #include "resource.h"
  6. //
  7. // Modifies the Tray notification icon.
  8. //
  9. BOOL Tray_Message(HWND hDlg, DWORD dwMessage, UINT uID, HICON hIcon, LPTSTR pszTip)
  10. {
  11. NOTIFYICONDATA tnd;
  12. tnd.cbSize = sizeof(NOTIFYICONDATA);
  13. tnd.hWnd = hDlg;
  14. tnd.uID = uID;
  15. tnd.uFlags = NIF_MESSAGE|NIF_ICON;
  16. tnd.uCallbackMessage = TRAY_NOTIFY;
  17. tnd.hIcon = hIcon;
  18. // Work out what tip we sould use and set NIF_TIP
  19. *tnd.szTip=0;
  20. if (pszTip)
  21. {
  22. if(HIWORD(pszTip))
  23. {
  24. lstrcpyn(tnd.szTip, pszTip, sizeof(tnd.szTip));
  25. tnd.uFlags |= NIF_TIP;
  26. }
  27. else
  28. {
  29. if( LoadString(vhinstCur, LOWORD(pszTip), tnd.szTip, sizeof(tnd.szTip) ) )
  30. tnd.uFlags |= NIF_TIP;
  31. }
  32. }
  33. return Shell_NotifyIcon(dwMessage, &tnd);
  34. }
  35. //
  36. // Removes the icon from the Tray.
  37. //
  38. BOOL Tray_Delete(HWND hDlg)
  39. {
  40. return Tray_Message(hDlg, NIM_DELETE, 0, NULL, NULL);
  41. }
  42. //
  43. //
  44. //
  45. BOOL Tray_Add(HWND hDlg, UINT uIndex)
  46. {
  47. HICON hIcon;
  48. DEBUG_PRINT(("Tray_Add used: Should use Tray_Modify instead"));
  49. if(!(hIcon = LoadImage(vhinstCur, MAKEINTRESOURCE(uIndex), IMAGE_ICON, 16, 16, 0)))
  50. return FALSE;
  51. return Tray_Message(hDlg, NIM_ADD, 0, hIcon, NULL);
  52. }
  53. //
  54. // Will add the tray icon if its not already there. LPTSTR can be a MAKEINTRESOURCE
  55. // If uIndex is NULL then we are to remove the tip
  56. //
  57. BOOL Tray_Modify(HWND hDlg, UINT uIndex, LPTSTR pszTip)
  58. {
  59. HICON hIcon;
  60. if( !uIndex )
  61. return Tray_Delete(hDlg);
  62. if(!(hIcon = LoadImage(vhinstCur, MAKEINTRESOURCE(uIndex), IMAGE_ICON, 16, 16, 0)))
  63. {
  64. DEBUG_PRINT(("Tray_Add: LoadIcon failed for icon %d\n",uIndex));
  65. return FALSE;
  66. }
  67. // If the notify fails, try adding the icon.
  68. if(!Tray_Message(hDlg, NIM_MODIFY, 0, hIcon, pszTip))
  69. return Tray_Message(hDlg, NIM_ADD, 0, hIcon, pszTip);
  70. return TRUE;
  71. }