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.

217 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. icon.cpp
  5. Abstract:
  6. This module implements icon handling code for the protected storage
  7. explorer.
  8. The shell uses these interfaces to retrieve icons associated with
  9. folders in the protected storage namespace.
  10. Author:
  11. Scott Field (sfield) 11-Mar-97
  12. --*/
  13. #include <windows.h>
  14. #include <shlobj.h>
  15. #include "pstore.h"
  16. #include "enumid.h"
  17. #include "utility.h"
  18. #include "icon.h"
  19. #include "resource.h"
  20. extern HINSTANCE g_hInst;
  21. extern LONG g_DllRefCount;
  22. CExtractIcon::CExtractIcon(
  23. LPCITEMIDLIST pidl
  24. )
  25. {
  26. //
  27. // squirrel away the type value and key type associated with the specified
  28. // pidl
  29. //
  30. m_dwType = GetPidlType(pidl);
  31. m_KeyType = GetPidlKeyType(pidl);
  32. m_ObjRefCount = 1;
  33. }
  34. CExtractIcon::~CExtractIcon()
  35. {
  36. }
  37. STDMETHODIMP
  38. CExtractIcon::QueryInterface(
  39. REFIID riid,
  40. LPVOID *ppReturn
  41. )
  42. {
  43. *ppReturn = NULL;
  44. if(IsEqualIID(riid, IID_IUnknown))
  45. *ppReturn = (IUnknown*)(IExtractIcon*)this;
  46. else if(IsEqualIID(riid, IID_IExtractIcon))
  47. *ppReturn = (IUnknown*)(IExtractIcon*)this;
  48. if(*ppReturn == NULL)
  49. return E_NOINTERFACE;
  50. (*(LPUNKNOWN*)ppReturn)->AddRef();
  51. return S_OK;
  52. }
  53. STDMETHODIMP_(DWORD)
  54. CExtractIcon::AddRef()
  55. {
  56. return InterlockedIncrement(&m_ObjRefCount);
  57. }
  58. STDMETHODIMP_(DWORD)
  59. CExtractIcon::Release()
  60. {
  61. LONG lDecremented = InterlockedDecrement(&m_ObjRefCount);
  62. if(lDecremented == 0)
  63. delete this;
  64. return lDecremented;
  65. }
  66. STDMETHODIMP
  67. CExtractIcon::GetIconLocation(
  68. UINT uFlags,
  69. LPTSTR szIconFile,
  70. UINT cchMax,
  71. LPINT piIndex,
  72. LPUINT puFlags
  73. )
  74. {
  75. //
  76. // tell the shell to always call Extract
  77. //
  78. *puFlags = GIL_NOTFILENAME;
  79. if(uFlags & GIL_OPENICON) {
  80. *piIndex = 1; // tell Extract to return the open icon
  81. } else {
  82. *piIndex = 0;
  83. //
  84. // if the icon request is associated with the "global" local machine,
  85. // and is at the Type or Subtype level, display a different icon.
  86. //
  87. if( m_KeyType == PST_KEY_LOCAL_MACHINE &&
  88. (m_dwType == PIDL_TYPE_TYPE || m_dwType == PIDL_TYPE_SUBTYPE) )
  89. *piIndex = 2;
  90. }
  91. return NOERROR;
  92. }
  93. STDMETHODIMP
  94. CExtractIcon::Extract(
  95. LPCTSTR pszFile,
  96. UINT nIconIndex,
  97. HICON *phiconLarge,
  98. HICON *phiconSmall,
  99. UINT nIconSize
  100. )
  101. {
  102. LPTSTR Resource;
  103. UINT nIconSizeLarge = (UINT)LOWORD(nIconSize);
  104. UINT nIconSizeSmall = (UINT)HIWORD(nIconSize);
  105. //
  106. // note icons are cached for performance reasons.
  107. //
  108. switch (nIconIndex) {
  109. case 0:
  110. static UINT nIconSizeSmallFolder;
  111. static UINT nIconSizeLargeFolder;
  112. static HICON hIconSmallFolder;
  113. static HICON hIconLargeFolder;
  114. Resource = MAKEINTRESOURCE(IDI_FOLDER);
  115. if(nIconSizeSmall != nIconSizeSmallFolder) {
  116. hIconSmallFolder = (HICON)LoadImage(g_hInst, Resource, IMAGE_ICON, nIconSizeSmall, nIconSizeSmall, LR_DEFAULTCOLOR | LR_SHARED);
  117. nIconSizeSmallFolder = nIconSizeSmall;
  118. }
  119. *phiconSmall = hIconSmallFolder;
  120. if(nIconSizeLarge != nIconSizeLargeFolder) {
  121. hIconLargeFolder = (HICON)LoadImage(g_hInst, Resource, IMAGE_ICON, nIconSizeLarge, nIconSizeLarge, LR_DEFAULTCOLOR | LR_SHARED);
  122. nIconSizeLargeFolder = nIconSizeLarge;
  123. }
  124. *phiconLarge = hIconLargeFolder;
  125. return S_OK;
  126. case 1:
  127. static UINT nIconSizeSmallFolderOpen;
  128. static UINT nIconSizeLargeFolderOpen;
  129. static HICON hIconSmallFolderOpen;
  130. static HICON hIconLargeFolderOpen;
  131. Resource = MAKEINTRESOURCE(IDI_FOLDEROPEN);
  132. if(nIconSizeSmall != nIconSizeSmallFolderOpen) {
  133. hIconSmallFolderOpen = (HICON)LoadImage(g_hInst, Resource, IMAGE_ICON, nIconSizeSmall, nIconSizeSmall, LR_DEFAULTCOLOR | LR_SHARED);
  134. nIconSizeSmallFolderOpen = nIconSizeSmall;
  135. }
  136. *phiconSmall = hIconSmallFolderOpen;
  137. if(nIconSizeLarge != nIconSizeLargeFolderOpen) {
  138. hIconLargeFolderOpen = (HICON)LoadImage(g_hInst, Resource, IMAGE_ICON, nIconSizeLarge, nIconSizeLarge, LR_DEFAULTCOLOR | LR_SHARED);
  139. nIconSizeLargeFolderOpen = nIconSizeLarge;
  140. }
  141. *phiconLarge = hIconLargeFolderOpen;
  142. return S_OK;
  143. case 2:
  144. static UINT nIconSizeSmallGlobal;
  145. static UINT nIconSizeLargeGlobal;
  146. static HICON hIconSmallGlobal;
  147. static HICON hIconLargeGlobal;
  148. Resource = MAKEINTRESOURCE(IDI_GLOBAL);
  149. if(nIconSizeSmall != nIconSizeSmallGlobal) {
  150. hIconSmallGlobal = (HICON)LoadImage(g_hInst, Resource, IMAGE_ICON, nIconSizeSmall, nIconSizeSmall, LR_DEFAULTCOLOR | LR_SHARED);
  151. nIconSizeSmallGlobal = nIconSizeSmall;
  152. }
  153. *phiconSmall = hIconSmallGlobal;
  154. if(nIconSizeLarge != nIconSizeLargeGlobal) {
  155. hIconLargeGlobal = (HICON)LoadImage(g_hInst, Resource, IMAGE_ICON, nIconSizeLarge, nIconSizeLarge, LR_DEFAULTCOLOR | LR_SHARED);
  156. nIconSizeLargeGlobal = nIconSizeLarge;
  157. }
  158. *phiconLarge = hIconLargeGlobal;
  159. return S_OK;
  160. default:
  161. return S_FALSE;
  162. }
  163. }