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.

118 lines
3.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: extract.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // ExtractIcon.cpp : Implementation of CExtractIcon
  11. #include "stdafx.h"
  12. #include "shlobj.h"
  13. #include "Extract.h"
  14. #include "xmlfile.h"
  15. /* 7A80E4A8-8005-11D2-BCF8-00C04F72C717 */
  16. CLSID CLSID_ExtractIcon = {0x7a80e4a8, 0x8005, 0x11d2, {0xbc, 0xf8, 0x00, 0xc0, 0x4f, 0x72, 0xc7, 0x17} };
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CExtractIcon
  19. STDMETHODIMP
  20. CExtractIcon::Extract(LPCTSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
  21. {
  22. HRESULT hr = S_OK;
  23. int nLargeIconSize = LOWORD(nIconSize);
  24. int nSmallIconSize = HIWORD(nIconSize);
  25. // extract from the .msc file ONLY if the file is in local storage, NOT in offline storage.
  26. DWORD dwFileAttributes = GetFileAttributes(pszFile);
  27. bool bUseMSCFile = (dwFileAttributes != 0xFFFFFFFF) && !(dwFileAttributes & FILE_ATTRIBUTE_OFFLINE);
  28. CSmartIcon iconLarge;
  29. CSmartIcon iconSmall;
  30. if (bUseMSCFile)
  31. {
  32. CPersistableIcon persistableIcon;
  33. // try to read file as if it was XML document first,
  34. hr = ExtractIconFromXMLFile (pszFile, persistableIcon);
  35. // if it fails, assume the file has older MSC format (compound document)
  36. // and try to read it
  37. if (FAILED (hr))
  38. {
  39. USES_CONVERSION;
  40. hr = persistableIcon.Load (T2CW (pszFile));
  41. }
  42. /*
  43. * get the large and small icons; if either of these fail,
  44. * we'll get default icons below
  45. */
  46. if (SUCCEEDED (hr) &&
  47. SUCCEEDED (hr = persistableIcon.GetIcon (nLargeIconSize, iconLarge)) &&
  48. SUCCEEDED (hr = persistableIcon.GetIcon (nSmallIconSize, iconSmall)))
  49. {
  50. ASSERT ((iconLarge != NULL) && (iconSmall != NULL));
  51. }
  52. }
  53. /*
  54. * use the default icons if the file is offline, or the Load failed
  55. */
  56. if (!bUseMSCFile || FAILED(hr))
  57. {
  58. /*
  59. * load the large and small icons from our resources
  60. */
  61. iconLarge.Attach ((HICON) LoadImage (_Module.GetModuleInstance(),
  62. MAKEINTRESOURCE(IDR_MAINFRAME),
  63. IMAGE_ICON,
  64. nLargeIconSize,
  65. nLargeIconSize,
  66. LR_DEFAULTCOLOR));
  67. iconSmall.Attach ((HICON) LoadImage (_Module.GetModuleInstance(),
  68. MAKEINTRESOURCE(IDR_MAINFRAME),
  69. IMAGE_ICON,
  70. nSmallIconSize,
  71. nSmallIconSize,
  72. LR_DEFAULTCOLOR));
  73. }
  74. /*
  75. * if we successfully got the large and small icons, return them
  76. * to the shell (which will take responsibility for their destruction)
  77. */
  78. if ((iconLarge != NULL) && (iconSmall != NULL))
  79. {
  80. *phiconLarge = iconLarge.Detach();
  81. *phiconSmall = iconSmall.Detach();
  82. hr = S_OK;
  83. }
  84. else
  85. hr = E_FAIL;
  86. return (hr);
  87. }
  88. STDMETHODIMP
  89. CExtractIcon::GetIconLocation(UINT uFlags, LPTSTR szIconFile, UINT cchMax, LPINT piIndex, UINT *pwFlags)
  90. {
  91. _tcscpy(szIconFile, (LPCTSTR)m_strIconFile);
  92. *piIndex = 0;
  93. *pwFlags = GIL_NOTFILENAME | GIL_PERINSTANCE | GIL_DONTCACHE;
  94. return NOERROR;
  95. }
  96. STDMETHODIMP
  97. CExtractIcon::Load(LPCOLESTR pszFileName, DWORD dwMode)
  98. {
  99. m_strIconFile = pszFileName;
  100. return S_OK;
  101. }