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.

249 lines
6.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000
  6. //
  7. // File: cputil.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef __CONTROLPANEL_UTIL_H
  11. #define __CONTROLPANEL_UTIL_H
  12. namespace CPL {
  13. enum eCPIMGSIZE
  14. {
  15. eCPIMGSIZE_WEBVIEW,
  16. eCPIMGSIZE_TASK,
  17. eCPIMGSIZE_CATEGORY,
  18. eCPIMGSIZE_BANNER,
  19. eCPIMGSIZE_APPLET,
  20. eCPIMGSIZE_NUMSIZES
  21. };
  22. class ICplView; // fwd decl.
  23. void ImageDimensionsFromDesiredSize(eCPIMGSIZE eSize, UINT *pcx, UINT *pcy);
  24. bool ShouldUseSmallIconForDesiredSize(eCPIMGSIZE eSize);
  25. HRESULT LoadIconFromResource(LPCWSTR pszResource, eCPIMGSIZE eSize, HICON *phIcon);
  26. HRESULT LoadIconFromResourceID(LPCWSTR pszModule, int idIcon, eCPIMGSIZE eSize, HICON *phIcon);
  27. HRESULT LoadIconFromResourceIndex(LPCWSTR pszModule, int iIcon, eCPIMGSIZE eSize, HICON *phIcon);
  28. HRESULT ExtractIconFromPidl(IShellFolder *psf, LPCITEMIDLIST pidl, eCPIMGSIZE eSize, HICON *phIcon);
  29. HRESULT LoadStringFromResource(LPCWSTR pszStrDesc, LPWSTR *ppszOut);
  30. HRESULT ShellBrowserFromSite(IUnknown *punkSite, IShellBrowser **ppsb);
  31. HRESULT ControlPanelViewFromSite(IUnknown *punkSite, ICplView **ppview);
  32. HRESULT BrowseIDListInPlace(LPCITEMIDLIST pidl, IShellBrowser *psb);
  33. HRESULT BuildHssHelpURL(LPCWSTR pszSelect, LPWSTR pszURL, UINT cchURL);
  34. HRESULT GetControlPanelFolder(IShellFolder **ppsf);
  35. HRESULT ExpandEnvironmentVars(LPCTSTR psz, LPTSTR *ppszOut);
  36. HRESULT SetControlPanelBarricadeStatus(VARIANT_BOOL vtb);
  37. bool IsAppletEnabled(LPCWSTR pszFilename, LPCWSTR pszName);
  38. bool IsSystemRestoreRestricted(void);
  39. BOOL IsConnectedToDomain(void);
  40. BOOL IsOsServer(void);
  41. BOOL IsOsPersonal(void);
  42. BOOL IsOsProfessional(void);
  43. BOOL IsUserAdmin(void);
  44. VARIANT_BOOL GetBarricadeStatus(bool *pbFixedByPolicy = NULL);
  45. bool IsFirstRunForThisUser(void);
  46. bool CategoryViewIsActive(bool *pbBarricadeFixedByPolicy = NULL);
  47. //
  48. // The default tab indices of the various tabs
  49. // if you add another tab, make sure its in the right position.
  50. // Note that desk.cpl respects these indices. The new themes tab
  51. // does not have an associated index, it is the default tab if
  52. // no index is specified.
  53. //
  54. enum eDESKCPLTAB {
  55. CPLTAB_ABSENT = -1,
  56. CPLTAB_DESK_BACKGROUND,
  57. CPLTAB_DESK_SCREENSAVER,
  58. CPLTAB_DESK_APPEARANCE,
  59. CPLTAB_DESK_SETTINGS,
  60. CPLTAB_DESK_MAX
  61. };
  62. int DeskCPL_GetTabIndex(eDESKCPLTAB eTab, OPTIONAL LPWSTR pszCanonicalName, OPTIONAL DWORD cchSize);
  63. bool DeskCPL_IsTabPresent(eDESKCPLTAB eTab);
  64. enum eACCOUNTTYPE
  65. {
  66. eACCOUNTTYPE_UNKNOWN = -1,
  67. eACCOUNTTYPE_OWNER,
  68. eACCOUNTTYPE_STANDARD,
  69. eACCOUNTTYPE_LIMITED,
  70. eACCOUNTTYPE_GUEST,
  71. eACCOUNTTYPE_NUMTYPES
  72. };
  73. HRESULT GetUserAccountType(eACCOUNTTYPE *pType);
  74. //
  75. // Each one of these "CpaDestroyer_XXXX" classes implements a single
  76. // "Destroy" function to free one item held in a DPA. Currently there
  77. // are only two flavors, one that calls "delete" and one that calls
  78. // "LocalFree". By default the CDpa class uses the CDpaDestoyer_Delete
  79. // class as that is the most commont form of freeing required. To use
  80. // another type, just specify another similar class as the 'D' template
  81. // argument to CDpa.
  82. //
  83. template <typename T>
  84. class CDpaDestroyer_Delete
  85. {
  86. public:
  87. static void Destroy(T* p)
  88. { delete p; }
  89. };
  90. template <typename T>
  91. class CDpaDestroyer_Free
  92. {
  93. public:
  94. static void Destroy(T* p)
  95. { if (p) LocalFree(p); }
  96. };
  97. template <typename T>
  98. class CDpaDestroyer_ILFree
  99. {
  100. public:
  101. static void Destroy(T* p)
  102. { if (p) ILFree(p); }
  103. };
  104. template <typename T>
  105. class CDpaDestroyer_Release
  106. {
  107. public:
  108. static void Destroy(T* p)
  109. { if (p) p->Release(); }
  110. };
  111. class CDpaDestroyer_None
  112. {
  113. public:
  114. static void Destroy(void*)
  115. { }
  116. };
  117. //-----------------------------------------------------------------------------
  118. // CDpa - Template class.
  119. //
  120. // Simplifies working with a DPA.
  121. //-----------------------------------------------------------------------------
  122. template <typename T, typename D = CDpaDestroyer_Delete<T> >
  123. class CDpa
  124. {
  125. public:
  126. explicit CDpa(int cGrow = 4)
  127. : m_hdpa(DPA_Create(cGrow)) { }
  128. ~CDpa(void) { _Destroy(); }
  129. bool IsValid(void) const { return NULL != m_hdpa; }
  130. int Count(void) const
  131. {
  132. return IsValid() ? DPA_GetPtrCount(m_hdpa) : 0;
  133. }
  134. const T* Get(int i) const
  135. {
  136. ASSERT(IsValid());
  137. ASSERT(i >= 0 && i < Count());
  138. return (const T*)DPA_GetPtr(m_hdpa, i);
  139. }
  140. T* Get(int i)
  141. {
  142. ASSERT(IsValid());
  143. ASSERT(i >= 0 && i < Count());
  144. return (T*)DPA_GetPtr(m_hdpa, i);
  145. }
  146. const T* operator [](int i) const
  147. {
  148. return Get(i);
  149. }
  150. T* operator [](int i)
  151. {
  152. return Get(i);
  153. }
  154. void Set(int i, T* p)
  155. {
  156. ASSERT(IsValid());
  157. ASSERT(i < Count());
  158. DPA_SetPtr(m_hdpa, i, p);
  159. }
  160. int Append(T* p)
  161. {
  162. ASSERT(IsValid());
  163. return DPA_AppendPtr(m_hdpa, p);
  164. }
  165. T* Remove(int i)
  166. {
  167. ASSERT(IsValid());
  168. ASSERT(i >= 0 && i < Count());
  169. return (T*)DPA_DeletePtr(m_hdpa, i);
  170. }
  171. void Clear(void)
  172. {
  173. _DestroyItems();
  174. }
  175. private:
  176. HDPA m_hdpa;
  177. void _DestroyItems(void)
  178. {
  179. if (NULL != m_hdpa)
  180. {
  181. while(0 < Count())
  182. {
  183. D::Destroy(Remove(0));
  184. }
  185. }
  186. }
  187. void _Destroy(void)
  188. {
  189. if (NULL != m_hdpa)
  190. {
  191. _DestroyItems();
  192. DPA_Destroy(m_hdpa);
  193. m_hdpa = NULL;
  194. }
  195. }
  196. //
  197. // Prevent copy.
  198. //
  199. CDpa(const CDpa& rhs);
  200. CDpa& operator = (const CDpa& rhs);
  201. };
  202. } // namespace CPL
  203. #endif // __CONTROLPANEL_UTIL_H