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.

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