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.

292 lines
6.6 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: tasks.cxx
  7. //
  8. // Contents: Tray notification icon for Job Scheduler service.
  9. //
  10. // Classes: CTrayIcon
  11. //
  12. // Functions: None.
  13. //
  14. // History: 3/22/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include "..\pch\headers.hxx"
  18. #pragma hdrstop
  19. #include <svc_core.hxx>
  20. #include "tasks.hxx"
  21. extern HINSTANCE g_hInstance;
  22. extern HWND g_hwndSchedSvc;
  23. //____________________________________________________________________________
  24. //
  25. // Member: CTrayIcon::_TrayMessage
  26. //
  27. // Synopsis: S
  28. //
  29. // Arguments: [dwMessage] -- IN Msg to Shell_NotifyIcon
  30. // [uiIcon] -- IN Tray icon id
  31. // [ids] -- IN Tool tip string id.
  32. //
  33. // Returns: HRESULT.
  34. //
  35. // History: 3/22/1996 RaviR Created
  36. //
  37. //____________________________________________________________________________
  38. BOOL
  39. CTrayIcon::_TrayMessage(
  40. DWORD dwMessage,
  41. UINT uiIcon,
  42. int ids)
  43. {
  44. NOTIFYICONDATA tnd;
  45. schDebugOut((DEB_ITRACE,
  46. "_TrayMessage: g_hwndSchedSvc = %x, dwMessage = %s, "
  47. "uiIcon = %u\n",
  48. g_hwndSchedSvc,
  49. dwMessage == NIM_ADD ? "NIM_ADD" :
  50. dwMessage == NIM_MODIFY ? "NIM_MODIFY" : "NIM_DELETE",
  51. uiIcon));
  52. tnd.cbSize = sizeof(NOTIFYICONDATA);
  53. tnd.hWnd = g_hwndSchedSvc;
  54. tnd.uID = 0;
  55. tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
  56. tnd.uCallbackMessage = SCHEDM_TRAY_NOTIFY;
  57. if (m_hTrayIcon != NULL)
  58. {
  59. DestroyIcon(m_hTrayIcon);
  60. m_hTrayIcon = NULL;
  61. }
  62. if (uiIcon != NULL)
  63. {
  64. m_hTrayIcon = (HICON)LoadImage(g_hInstance, MAKEINTRESOURCE(uiIcon),
  65. IMAGE_ICON, 16, 16, 0);
  66. }
  67. tnd.hIcon = m_hTrayIcon;
  68. if (ids != 0)
  69. {
  70. LoadString(g_hInstance, ids, tnd.szTip, sizeof(tnd.szTip));
  71. }
  72. else
  73. {
  74. tnd.szTip[0] = TEXT('\0');
  75. }
  76. return Shell_NotifyIcon(dwMessage, &tnd);
  77. }
  78. //____________________________________________________________________________
  79. //
  80. // Function: Schedule_TrayNotify
  81. //
  82. // Synopsis: Notify handler for notifications from the scheduler tray icon.
  83. //
  84. // Arguments: [wParam] -- IN
  85. // [lParam] -- IN
  86. //
  87. // Returns: void
  88. //
  89. // History: 3/22/1996 RaviR Created
  90. //
  91. //____________________________________________________________________________
  92. void
  93. Schedule_TrayNotify(
  94. WPARAM wParam,
  95. LPARAM lParam)
  96. {
  97. if (lParam == WM_RBUTTONDOWN)
  98. {
  99. //
  100. // Popup the context menu. {open, pause}
  101. //
  102. HMENU popup;
  103. HMENU subpopup;
  104. POINT mousepos;
  105. popup = LoadMenu(g_hInstance,
  106. GetCurrentServiceState() == SERVICE_PAUSED ?
  107. MAKEINTRESOURCE(IDR_TRAY_ICON_POPUP_MENU_CONTINUE) :
  108. MAKEINTRESOURCE(IDR_TRAY_ICON_POPUP_MENU_PAUSE));
  109. if (popup)
  110. {
  111. int suspended;
  112. subpopup = GetSubMenu(popup, 0);
  113. if( subpopup )
  114. {
  115. SetMenuDefaultItem(subpopup, 0, MF_BYPOSITION);
  116. if (GetCursorPos(&mousepos))
  117. {
  118. SetForegroundWindow(g_hwndSchedSvc);
  119. TrackPopupMenuEx(subpopup, TPM_LEFTALIGN | TPM_LEFTBUTTON |
  120. TPM_RIGHTBUTTON, mousepos.x, mousepos.y,
  121. g_hwndSchedSvc, NULL);
  122. }
  123. RemoveMenu(popup, 0, MF_BYPOSITION);
  124. DestroyMenu(popup);
  125. DestroyMenu(subpopup);
  126. }
  127. else //if we failed clean up first
  128. {
  129. RemoveMenu(popup, 0, MF_BYPOSITION);
  130. DestroyMenu(popup);
  131. }
  132. }
  133. }
  134. else if (lParam == WM_LBUTTONDBLCLK)
  135. {
  136. OpenJobFolder();
  137. }
  138. }
  139. //____________________________________________________________________________
  140. //
  141. // Function: OpenJobFolder
  142. //
  143. // Synopsis: Opens the job folder on the local machine.
  144. //
  145. // Returns: void
  146. //
  147. // History: 3/22/1996 RaviR Created
  148. //
  149. //____________________________________________________________________________
  150. #define BREAK_ON_FAIL(hr) if (FAILED(hr)) { break; } else 1;
  151. #define CMD_ID_FIRST 1
  152. #define CMD_ID_LAST 0x7fff
  153. void
  154. OpenJobFolder(void)
  155. {
  156. //
  157. // Browse the jobs folder
  158. //
  159. HCURSOR hcWait = SetCursor(LoadCursor(NULL, IDC_WAIT));
  160. HRESULT hr = S_OK;
  161. LPSHELLFOLDER pshf = NULL;
  162. LPCONTEXTMENU pcm = NULL;
  163. HMENU hmenu = NULL;
  164. // "::CLSID_MyComputer\\::CLSID_TasksFolder"
  165. WCHAR buf1[200] = L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{d6277990-4c6a-11cf-8d87-00aa0060f5bf}";
  166. do
  167. {
  168. hr = SHGetDesktopFolder(&pshf);
  169. CHECK_HRESULT(hr);
  170. BREAK_ON_FAIL(hr);
  171. ULONG chEaten, dwAttributes;
  172. LPITEMIDLIST pidl;
  173. hr = pshf->ParseDisplayName(NULL, 0, buf1,
  174. &chEaten, &pidl, &dwAttributes);
  175. CHECK_HRESULT(hr);
  176. BREAK_ON_FAIL(hr);
  177. hr = pshf->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST *)&pidl,
  178. IID_IContextMenu, NULL, (void**)&pcm);
  179. CHECK_HRESULT(hr);
  180. BREAK_ON_FAIL(hr);
  181. hmenu = CreatePopupMenu();
  182. if (hmenu == NULL)
  183. {
  184. hr = E_OUTOFMEMORY;
  185. CHECK_HRESULT(hr);
  186. break;
  187. }
  188. #ifdef _CHICAGO_
  189. CMINVOKECOMMANDINFO ici = {
  190. sizeof(CMINVOKECOMMANDINFO),
  191. CMIC_MASK_ASYNCOK,
  192. NULL,
  193. NULL,
  194. NULL, NULL,
  195. SW_NORMAL,
  196. };
  197. #else
  198. CMINVOKECOMMANDINFOEX ici = {
  199. sizeof(CMINVOKECOMMANDINFOEX),
  200. CMIC_MASK_ASYNCOK,
  201. NULL,
  202. NULL,
  203. NULL, NULL,
  204. SW_NORMAL,
  205. };
  206. #endif
  207. UINT idCmd;
  208. UINT fFlags = CMF_DEFAULTONLY;
  209. hr = pcm->QueryContextMenu(hmenu, 0, CMD_ID_FIRST,
  210. CMD_ID_LAST, fFlags);
  211. CHECK_HRESULT(hr);
  212. BREAK_ON_FAIL(hr);
  213. idCmd = GetMenuDefaultItem(hmenu, MF_BYCOMMAND, 0);
  214. SetCursor(hcWait);
  215. hcWait = NULL;
  216. if (idCmd)
  217. {
  218. ici.lpVerb = (LPSTR)MAKEINTRESOURCE(idCmd - CMD_ID_FIRST);
  219. hr = pcm->InvokeCommand((LPCMINVOKECOMMANDINFO)&ici);
  220. CHECK_HRESULT(hr);
  221. }
  222. } while (0);
  223. if (hmenu != NULL)
  224. {
  225. DestroyMenu(hmenu);
  226. }
  227. if (pcm != NULL)
  228. {
  229. pcm->Release();
  230. }
  231. if (pshf != NULL)
  232. {
  233. pshf->Release();
  234. }
  235. if (hcWait != NULL)
  236. {
  237. SetCursor(hcWait);
  238. }
  239. }