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.

133 lines
3.1 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 000
  5. *
  6. * File: xmlicon.cpp
  7. *
  8. * Contents: Implementation file for CXMLIcon
  9. *
  10. * History: 26-Jul-2000 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #include "xmlicon.h"
  14. #include "xmlimage.h"
  15. #include <atlapp.h>
  16. #include <atlgdi.h>
  17. /*+-------------------------------------------------------------------------*
  18. * ScGetIconSize
  19. *
  20. * Returns the width/height of a given icon (the width and height of icons
  21. * are always equal).
  22. *--------------------------------------------------------------------------*/
  23. SC ScGetIconSize (HICON hIcon, int& nIconSize)
  24. {
  25. DECLARE_SC (sc, _T("ScGetIconSize"));
  26. ICONINFO ii;
  27. if (!GetIconInfo (hIcon, &ii))
  28. return (sc.FromLastError());
  29. /*
  30. * GetIconInfo creates bitmaps that we're responsible for deleting;
  31. * attach the bitmaps to smart objects so cleanup is assured
  32. */
  33. WTL::CBitmap bmMask = ii.hbmMask;
  34. WTL::CBitmap bmColor = ii.hbmColor;
  35. /*
  36. * get the dimensions of the mask bitmap (don't use the color bitmap,
  37. * since that's not present for monochrome icons)
  38. */
  39. BITMAP bmData;
  40. if (!bmMask.GetBitmap (bmData))
  41. return (sc.FromLastError());
  42. nIconSize = bmData.bmWidth;
  43. return (sc);
  44. }
  45. /*+-------------------------------------------------------------------------*
  46. * CXMLIcon::Persist
  47. *
  48. * Saves/loads a CXMLIcon to a CPersistor.
  49. *--------------------------------------------------------------------------*/
  50. void CXMLIcon::Persist (CPersistor &persistor)
  51. {
  52. DECLARE_SC (sc, _T("CXMLIcon::Persist"));
  53. CXMLImageList iml;
  54. try
  55. {
  56. if (persistor.IsStoring())
  57. {
  58. ASSERT (operator HICON() != NULL);
  59. /*
  60. * find out how big the icon is
  61. */
  62. int cxIcon;
  63. sc = ScGetIconSize (*this, cxIcon);
  64. if (sc)
  65. sc.Throw();
  66. /*
  67. * create an imagelist to accomodate it
  68. */
  69. if (!iml.Create (cxIcon, cxIcon, ILC_COLOR16 | ILC_MASK, 1, 1))
  70. sc.FromLastError().Throw();
  71. /*
  72. * add the icon to the imagelist
  73. */
  74. if (iml.AddIcon(*this) == -1)
  75. sc.FromLastError().Throw();
  76. }
  77. iml.Persist (persistor);
  78. if (persistor.IsLoading())
  79. {
  80. /*
  81. * extract the icon from the imagelist
  82. */
  83. Attach (iml.GetIcon (0));
  84. }
  85. }
  86. catch (...)
  87. {
  88. /*
  89. * WTL::CImageList doesn't auto-destroy its HIMAGELIST, so we have to do it manually
  90. */
  91. iml.Destroy();
  92. throw;
  93. }
  94. /*
  95. * WTL::CImageList doesn't auto-destroy its HIMAGELIST, so we have to do it manually
  96. */
  97. iml.Destroy();
  98. }
  99. /*+-------------------------------------------------------------------------*
  100. * CXMLIcon::GetBinaryEntryName
  101. *
  102. * Returns the name to be attached to this CXMLIcon's entry in the XML
  103. * binary data collection.
  104. *--------------------------------------------------------------------------*/
  105. LPCTSTR CXMLIcon::GetBinaryEntryName()
  106. {
  107. if (m_strBinaryEntryName.empty())
  108. return (NULL);
  109. return (m_strBinaryEntryName.data());
  110. }