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.

122 lines
3.0 KiB

  1. #include "shellprv.h"
  2. #pragma hdrstop
  3. #include "pidl.h"
  4. #include "ids.h"
  5. #include "drives.h"
  6. #include "mtpt.h"
  7. #include "shitemid.h"
  8. #include "xiconwrap.h"
  9. #include "hwcmmn.h"
  10. // From drivfldr.cpp
  11. int _GetSHID(int iDrive);
  12. class CDrvExtIconBase : public CExtractIconBase
  13. {
  14. public:
  15. HRESULT _GetIconLocationW(UINT uFlags, LPWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags);
  16. HRESULT _ExtractW(LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize);
  17. HRESULT _Init(LPCWSTR pszDrive)
  18. {
  19. _pszDrive = StrDup(pszDrive);
  20. return _pszDrive ? S_OK : E_OUTOFMEMORY;
  21. }
  22. CDrvExtIconBase() : CExtractIconBase(), _pszDrive(NULL) {}
  23. protected:
  24. ~CDrvExtIconBase();
  25. private:
  26. LPWSTR _pszDrive;
  27. };
  28. CDrvExtIconBase::~CDrvExtIconBase()
  29. {
  30. LocalFree((HLOCAL)_pszDrive); // accepts NULL
  31. }
  32. STDAPI SHCreateDrvExtIcon(LPCWSTR pszDrive, REFIID riid, void **ppv)
  33. {
  34. HRESULT hr;
  35. CDrvExtIconBase* pdeib = new CDrvExtIconBase();
  36. if (pdeib)
  37. {
  38. hr = pdeib->_Init(pszDrive);
  39. if (SUCCEEDED(hr))
  40. hr = pdeib->QueryInterface(riid, ppv);
  41. pdeib->Release();
  42. }
  43. else
  44. {
  45. hr = E_OUTOFMEMORY;
  46. }
  47. return hr;
  48. }
  49. HRESULT CDrvExtIconBase::_GetIconLocationW(UINT uFlags, LPWSTR pszIconFile,
  50. UINT cchMax, int *piIndex, UINT *pwFlags)
  51. {
  52. HRESULT hr = S_OK;
  53. pszIconFile[0] = 0;
  54. if (uFlags & GIL_DEFAULTICON)
  55. {
  56. *piIndex = CMountPoint::GetSuperPlainDriveIcon(_pszDrive,
  57. GetDriveType(_pszDrive));
  58. hr = StringCchCopy(pszIconFile, cchMax, TEXT("shell32.dll"));
  59. *pwFlags = GIL_PERCLASS;
  60. // Make sure our default icon makes it to the cache
  61. Shell_GetCachedImageIndex(c_szShell32Dll, *piIndex, *pwFlags);
  62. }
  63. else
  64. {
  65. if (!(uFlags & GIL_ASYNC))
  66. {
  67. CMountPoint* pmtpt = CMountPoint::GetMountPoint(_pszDrive);
  68. if (pmtpt)
  69. {
  70. *piIndex = pmtpt->GetIcon(pszIconFile, cchMax);
  71. if (!*pszIconFile)
  72. {
  73. GetModuleFileName(HINST_THISDLL, pszIconFile, cchMax);
  74. }
  75. pmtpt->StoreIconForUpdateImage(Shell_GetCachedImageIndex(
  76. pszIconFile, *piIndex, 0));
  77. pmtpt->Release();
  78. }
  79. else
  80. {
  81. *piIndex = CMountPoint::GetSuperPlainDriveIcon(_pszDrive,
  82. GetDriveType(_pszDrive));
  83. hr = StringCchCopy(pszIconFile, cchMax, TEXT("shell32.dll"));
  84. }
  85. *pwFlags = GIL_PERCLASS;
  86. }
  87. else
  88. {
  89. hr = E_PENDING;
  90. }
  91. }
  92. return hr;
  93. }
  94. HRESULT CDrvExtIconBase::_ExtractW(LPCWSTR pszFile, UINT nIconIndex,
  95. HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
  96. {
  97. return SHDefExtractIcon(pszFile, nIconIndex, GIL_PERCLASS, phiconLarge,
  98. phiconSmall, nIconSize);
  99. }