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.

234 lines
5.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: I C O M T A R G . C P P
  7. //
  8. // Contents: ICommandTarget implementation for IConnectionTray
  9. //
  10. // Notes:
  11. //
  12. // Author: jeffspr 12 Nov 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "foldinc.h" // Standard shell\tray includes
  18. #include "ctrayui.h" // extern for the global tray object
  19. HRESULT CConnectionTray::QueryStatus(
  20. IN const GUID * pguidCmdGroup,
  21. IN ULONG cCmds,
  22. IN OUT OLECMD prgCmds[],
  23. IN OUT OLECMDTEXT * pCmdText)
  24. {
  25. TraceFileFunc(ttidShellFolderIface);
  26. HRESULT hr = E_NOTIMPL;
  27. TraceHr(ttidError, FAL, hr, (hr == E_NOTIMPL), "CConnectionTray::QueryStatus");
  28. return hr;
  29. }
  30. HRESULT CConnectionTray::Exec(
  31. IN const GUID * pguidCmdGroup,
  32. IN DWORD nCmdID,
  33. IN DWORD nCmdexecopt,
  34. IN VARIANTARG * pvaIn,
  35. IN OUT VARIANTARG * pvaOut)
  36. {
  37. TraceFileFunc(ttidShellFolderIface);
  38. HRESULT hr = S_OK;
  39. // Set the DisableTray flag in netcfg.ini to prevent the network connections
  40. // tray code from executing.
  41. //
  42. if (!FIsDebugFlagSet (dfidDisableTray))
  43. {
  44. if (IsEqualGUID(*pguidCmdGroup, CGID_ShellServiceObject))
  45. {
  46. // Handle Shell Service Object notifications here.
  47. switch (nCmdID)
  48. {
  49. case SSOCMDID_OPEN:
  50. TraceTag(ttidShellFolder, "The Net Connections Tray is being initialized");
  51. hr = HrHandleTrayOpen();
  52. break;
  53. case SSOCMDID_CLOSE:
  54. TraceTag(ttidShellFolder, "The Net Connections Tray is being destroyed");
  55. hr = HrHandleTrayClose();
  56. break;
  57. default:
  58. hr = S_OK;
  59. break;
  60. }
  61. }
  62. }
  63. TraceHr(ttidError, FAL, hr, FALSE, "CConnectionTray::Exec");
  64. return hr;
  65. }
  66. DWORD WINAPI TrayInitThreadProc(IN LPVOID lpParam)
  67. {
  68. HRESULT hr = S_OK;
  69. BOOL fCoInited = FALSE;
  70. hr = CoInitializeEx (NULL, COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);
  71. if (SUCCEEDED(hr))
  72. {
  73. // We don't care if this is S_FALSE or not, since we'll soon
  74. // overwrite the hr. If it's already initialized, great...
  75. fCoInited = TRUE;
  76. // Create the TrayUI object and save it in a global.
  77. //
  78. Assert(!g_pCTrayUI);
  79. if (!g_pCTrayUI)
  80. {
  81. g_pCTrayUI = new CTrayUI();
  82. if (!g_pCTrayUI)
  83. {
  84. hr = E_OUTOFMEMORY;
  85. }
  86. }
  87. // Initialize the tray UI object
  88. //
  89. if (g_pCTrayUI)
  90. {
  91. hr = g_pCTrayUI->HrInitTrayUI();
  92. }
  93. }
  94. MSG msg;
  95. while (GetMessage (&msg, 0, 0, 0))
  96. {
  97. DispatchMessage (&msg);
  98. }
  99. if (fCoInited)
  100. {
  101. CoUninitialize();
  102. }
  103. return hr;
  104. }
  105. //+---------------------------------------------------------------------------
  106. //
  107. // Member: CConnectionTray::HrHandleTrayOpen
  108. //
  109. // Purpose: Handler for the Net Connections Tray object ::Exec call
  110. // SSOCMDID_OPEN command
  111. //
  112. // Arguments:
  113. // (none)
  114. //
  115. // Returns:
  116. //
  117. // Author: jeffspr 7 Jan 1998
  118. //
  119. // Notes:
  120. //
  121. HRESULT CConnectionTray::HrHandleTrayOpen()
  122. {
  123. HRESULT hr = S_OK;
  124. // Turn off separate thread for Whistler. The proper way to do this is to register at runtime
  125. // a ShellServiceObject when UI is needed and de-register when not needed, using
  126. #if 0
  127. TraceTag(ttidShellFolder, "Starting tray thread proc");
  128. QueueUserWorkItem(TrayInitThreadProc, NULL, WT_EXECUTELONGFUNCTION);
  129. #else
  130. if (SUCCEEDED(hr))
  131. {
  132. // We don't care if this is S_FALSE or not, since we'll soon
  133. // overwrite the hr. If it's already initialized, great...
  134. // Create the TrayUI object and save it in a global.
  135. //
  136. Assert(!g_pCTrayUI);
  137. if (!g_pCTrayUI)
  138. {
  139. g_pCTrayUI = new CTrayUI();
  140. if (!g_pCTrayUI)
  141. {
  142. hr = E_OUTOFMEMORY;
  143. }
  144. }
  145. // Initialize the tray UI object
  146. //
  147. if (g_pCTrayUI)
  148. {
  149. hr = g_pCTrayUI->HrInitTrayUI();
  150. }
  151. // Add the Notify Sink
  152. if (SUCCEEDED(hr))
  153. {
  154. g_ccl.EnsureConPointNotifyAdded();
  155. }
  156. }
  157. #endif
  158. TraceHr(ttidError, FAL, hr, FALSE, "CConnectionTray::HrHandleTrayOpen()");
  159. return hr;
  160. }
  161. //+---------------------------------------------------------------------------
  162. //
  163. // Member: CConnectionTray::HrHandleTrayClose
  164. //
  165. // Purpose: Handler for the Net Connections Tray object ::Exec call
  166. // SSOCMDID_CLOSE command
  167. //
  168. // Arguments:
  169. // (none)
  170. //
  171. // Returns:
  172. //
  173. // Author: jeffspr 7 Jan 1998
  174. //
  175. // Notes:
  176. //
  177. HRESULT CConnectionTray::HrHandleTrayClose()
  178. {
  179. HRESULT hr = S_OK;
  180. g_ccl.EnsureConPointNotifyRemoved();
  181. if (g_pCTrayUI)
  182. {
  183. // Destroy the tray UI object
  184. //
  185. hr = g_pCTrayUI->HrDestroyTrayUI();
  186. // Check the outcome, and trace it if it failed, but ignore a failure,
  187. // and continue to destroy the object
  188. //
  189. TraceHr(ttidError, FAL, hr, FALSE,
  190. "Failed in call to g_pCTrayUI->HrDestroyTrayUI");
  191. // Delete the tray object
  192. //
  193. delete g_pCTrayUI;
  194. g_pCTrayUI = NULL;
  195. TraceTag(ttidShellFolder, "Deleted the connections tray object");
  196. }
  197. TraceHr(ttidError, FAL, hr, FALSE, "CConnectionTray::HrHandleTrayClose()");
  198. return hr;
  199. }