Source code of Windows XP (NT5)
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.

199 lines
4.6 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. BOOL fTrayIconShowing;
  4. TCHAR downloadFormatString[64];
  5. TCHAR pauseString[64];
  6. BOOL MyShell_NotifyIcon(DWORD dwMessage, PNOTIFYICONDATA pnid)
  7. {
  8. // DEBUGMSG("MyShell_NotifyIcon() called with msg %d", dwMessage);
  9. BOOL fRet;
  10. if (NIM_SETVERSION == dwMessage)
  11. {
  12. return Shell_NotifyIcon(dwMessage, pnid);
  13. }
  14. UINT uRetry = 0;
  15. //retry 3 times due to the way Shell_NotifyIcon is implemented
  16. while ( !(fRet = Shell_NotifyIcon(dwMessage, pnid)) && uRetry++ < 3)
  17. {
  18. if (WAIT_TIMEOUT != MsgWaitForMultipleObjectsEx(0,NULL, 2000, QS_POSTMESSAGE, MWMO_INPUTAVAILABLE))
  19. {
  20. break;
  21. }
  22. }
  23. return fRet;
  24. }
  25. void InitTrayIcon()
  26. {
  27. fTrayIconShowing = FALSE;
  28. TCHAR PauseMenuString[30];
  29. TCHAR ResumeMenuString[30];
  30. LoadString(ghInstance, IDS_PAUSEMENUITEM, PauseMenuString, ARRAYSIZE(PauseMenuString));
  31. LoadString(ghInstance, IDS_RESUMEMENUITEM, ResumeMenuString, ARRAYSIZE(ResumeMenuString));
  32. ghPauseMenu = CreatePopupMenu();
  33. AppendMenu(ghPauseMenu, MF_STRING, IDC_PAUSE, PauseMenuString);
  34. ghResumeMenu = CreatePopupMenu();
  35. AppendMenu(ghResumeMenu, MF_STRING, IDC_RESUME, ResumeMenuString);
  36. LoadString(ghInstance, IDS_DOWNLOADINGFORMAT, downloadFormatString, ARRAYSIZE(downloadFormatString));
  37. LoadString(ghInstance, IDS_SUSPENDEDFORMAT, pauseString, ARRAYSIZE(pauseString));
  38. }
  39. void UninitPopupMenus()
  40. {
  41. if (NULL != ghPauseMenu)
  42. {
  43. DestroyMenu(ghPauseMenu);
  44. }
  45. if (NULL != ghResumeMenu)
  46. {
  47. DestroyMenu(ghResumeMenu);
  48. }
  49. }
  50. BOOL ShowTrayIcon()
  51. {
  52. DEBUGMSG("ShowTrayIcon() called");
  53. if ( fTrayIconShowing)
  54. {
  55. return TRUE;
  56. }
  57. NOTIFYICONDATA nid;
  58. memset(&nid, 0, sizeof(nid));
  59. nid.cbSize = sizeof(nid);
  60. nid.hWnd = ghMainWindow;
  61. nid.uID = (UINT) IDI_AUICON;
  62. nid.uFlags = NIF_ICON | NIF_MESSAGE;
  63. nid.uCallbackMessage = AUMSG_TRAYCALLBACK;
  64. nid.hIcon = ghTrayIcon;
  65. BOOL fRet = MyShell_NotifyIcon(NIM_ADD, &nid);
  66. if(!fRet)
  67. {
  68. // If for any reason, we are not able to use the tray icon, something is wrong
  69. // ask WUAUSERV wait for sometime before relaunch WUAUCLT.
  70. DEBUGMSG("WUAUCLT quit because fail to add tray icon");
  71. SetClientExitCode(CDWWUAUCLT_RELAUNCHLATER);
  72. QUITAUClient();
  73. }
  74. else
  75. {
  76. fTrayIconShowing = TRUE;
  77. }
  78. return fRet;
  79. }
  80. void ShowTrayBalloon(WORD title, WORD caption, WORD tip )
  81. {
  82. DEBUGMSG("ShowTrayBalloon() called");
  83. static NOTIFYICONDATA nid;
  84. memset(&nid, 0, sizeof(nid));
  85. nid.uTimeout = 15000;
  86. LoadString(ghInstance, title, nid.szInfoTitle, ARRAYSIZE(nid.szInfoTitle));
  87. LoadString(ghInstance, caption, nid.szInfo, ARRAYSIZE(nid.szInfo));
  88. LoadString(ghInstance, tip, nid.szTip, ARRAYSIZE(nid.szTip));
  89. nid.uFlags = NIF_INFO | NIF_TIP;
  90. nid.cbSize = sizeof(nid);
  91. nid.hWnd = ghMainWindow;
  92. nid.uID = (UINT) IDI_AUICON;
  93. nid.dwInfoFlags = NIIF_INFO;
  94. BOOL fRet = MyShell_NotifyIcon(NIM_MODIFY, &nid);
  95. if (!fRet)
  96. {
  97. DEBUGMSG("WUAUCLT Creation of tray balloon failed");
  98. }
  99. #ifdef DBG
  100. DebugCheckForAutoPilot(ghMainWindow);
  101. #endif
  102. }
  103. /*
  104. void AddTrayToolTip(WORD tip)
  105. {
  106. static NOTIFYICONDATA nid;
  107. memset(&nid, 0, sizeof(nid));
  108. LoadString(ghInstance, tip, nid.szTip, ARRAYSIZE(nid.szTip));
  109. nid.uFlags = NIF_TIP;
  110. nid.cbSize = sizeof(nid);
  111. nid.hWnd = ghMainWindow;
  112. nid.uID = (UINT) IDI_AUICON;
  113. MyShell_NotifyIcon(NIM_MODIFY, &nid);
  114. }
  115. */
  116. void RemoveTrayIcon()
  117. {
  118. DEBUGMSG("RemoveTrayIcon() called");
  119. if (fTrayIconShowing)
  120. {
  121. NOTIFYICONDATA nid;
  122. memset(&nid, 0, sizeof(nid));
  123. nid.cbSize = sizeof(nid);
  124. nid.hWnd = ghMainWindow;
  125. nid.uID = (UINT) IDI_AUICON;
  126. MyShell_NotifyIcon(NIM_DELETE, &nid);
  127. // Don't leave any popup menu around when removing tray icon.
  128. if (SendMessage(ghMainWindow, WM_CANCELMODE, 0, 0))
  129. {
  130. DEBUGMSG("WUAUCLT WM_CANCELMODE was not handled");
  131. }
  132. fTrayIconShowing = FALSE;
  133. }
  134. }
  135. //fixcode: when download complete, should call ShowProgress() to update trayicon info
  136. void ShowProgress()
  137. {
  138. NOTIFYICONDATA nid;
  139. UINT percentComplete;
  140. DWORD status;
  141. //DEBUGMSG("ShowProgress() called");
  142. memset(&nid, 0, sizeof(nid));
  143. if (FAILED(gInternals->m_getDownloadStatus(&percentComplete, &status)))
  144. {
  145. QUITAUClient();
  146. return;
  147. }
  148. nid.cbSize = sizeof(nid);
  149. nid.hWnd = ghMainWindow;
  150. nid.uID = (UINT) IDI_AUICON;
  151. nid.uFlags = NIF_TIP;
  152. if(status == DWNLDSTATUS_DOWNLOADING)
  153. {
  154. (void)StringCchPrintfEx(nid.szTip, ARRAYSIZE(nid.szTip), NULL, NULL, MISTSAFE_STRING_FLAGS, downloadFormatString, percentComplete);
  155. }
  156. else if(status == DWNLDSTATUS_PAUSED)
  157. {
  158. (void)StringCchCopyEx(nid.szTip, ARRAYSIZE(nid.szTip), pauseString, NULL, NULL, MISTSAFE_STRING_FLAGS);
  159. }
  160. else
  161. {
  162. (void)StringCchCopyEx(nid.szTip, ARRAYSIZE(nid.szTip), _T(""), NULL, NULL, MISTSAFE_STRING_FLAGS);
  163. }
  164. MyShell_NotifyIcon(NIM_MODIFY, &nid);
  165. }