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.

208 lines
4.8 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1997 **/
  4. /**********************************************************************/
  5. /*
  6. about.cpp
  7. base class for the IAbout interface for MMC
  8. FILE HISTORY:
  9. */
  10. #include <stdafx.h>
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. DEBUG_DECLARE_INSTANCE_COUNTER(CAbout);
  17. CAbout::CAbout() :
  18. m_hSmallImage(NULL),
  19. m_hSmallImageOpen(NULL),
  20. m_hLargeImage(NULL),
  21. m_hAppIcon(NULL)
  22. {
  23. DEBUG_INCREMENT_INSTANCE_COUNTER(CAbout);
  24. }
  25. CAbout::~CAbout()
  26. {
  27. DEBUG_DECREMENT_INSTANCE_COUNTER(CAbout);
  28. if (m_hSmallImage)
  29. {
  30. DeleteObject(m_hSmallImage);
  31. }
  32. if (m_hSmallImageOpen)
  33. {
  34. DeleteObject(m_hSmallImageOpen);
  35. }
  36. if (m_hLargeImage)
  37. {
  38. DeleteObject(m_hLargeImage);
  39. }
  40. if (m_hAppIcon)
  41. {
  42. DeleteObject(m_hAppIcon);
  43. }
  44. }
  45. /*!--------------------------------------------------------------------------
  46. CAbout::AboutHelper
  47. Helper to get information from resource file
  48. Author:
  49. ---------------------------------------------------------------------------*/
  50. HRESULT
  51. CAbout::AboutHelper
  52. (
  53. UINT nID,
  54. LPOLESTR* lpPtr
  55. )
  56. {
  57. if (lpPtr == NULL)
  58. return E_POINTER;
  59. CString s;
  60. // Needed for Loadstring
  61. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  62. HRESULT hr = hrOK;
  63. COM_PROTECT_TRY
  64. {
  65. s.LoadString(nID);
  66. *lpPtr = reinterpret_cast<LPOLESTR>
  67. (CoTaskMemAlloc((s.GetLength() + 1)* sizeof(wchar_t)));
  68. if (*lpPtr == NULL)
  69. return E_OUTOFMEMORY;
  70. lstrcpy(*lpPtr, (LPCTSTR)s);
  71. }
  72. COM_PROTECT_CATCH
  73. return hr;
  74. }
  75. /*!--------------------------------------------------------------------------
  76. CAbout::GetSnapinDescription
  77. MMC calls this to get the snapin's description
  78. Author:
  79. ---------------------------------------------------------------------------*/
  80. STDMETHODIMP
  81. CAbout::GetSnapinDescription
  82. (
  83. LPOLESTR* lpDescription
  84. )
  85. {
  86. return AboutHelper(GetAboutDescriptionId(), lpDescription);
  87. }
  88. /*!--------------------------------------------------------------------------
  89. CAbout::GetProvider
  90. MMC calls this to get the snapin's provider
  91. Author:
  92. ---------------------------------------------------------------------------*/
  93. STDMETHODIMP
  94. CAbout::GetProvider
  95. (
  96. LPOLESTR* lpName
  97. )
  98. {
  99. return AboutHelper(GetAboutProviderId(), lpName);
  100. }
  101. /*!--------------------------------------------------------------------------
  102. CAbout::AboutHelper
  103. MMC calls this to get the snapin's version
  104. Author:
  105. ---------------------------------------------------------------------------*/
  106. STDMETHODIMP
  107. CAbout::GetSnapinVersion
  108. (
  109. LPOLESTR* lpVersion
  110. )
  111. {
  112. return AboutHelper(GetAboutVersionId(), lpVersion);
  113. }
  114. /*!--------------------------------------------------------------------------
  115. CAbout::GetSnapinImage
  116. MMC calls this to get the snapin's icon
  117. Author:
  118. ---------------------------------------------------------------------------*/
  119. STDMETHODIMP
  120. CAbout::GetSnapinImage
  121. (
  122. HICON* hAppIcon
  123. )
  124. {
  125. if (hAppIcon == NULL)
  126. return E_POINTER;
  127. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  128. if (NULL == m_hAppIcon)
  129. {
  130. m_hAppIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(GetAboutIconId()));
  131. }
  132. *hAppIcon = m_hAppIcon;
  133. ASSERT(*hAppIcon != NULL);
  134. return (*hAppIcon != NULL) ? S_OK : E_FAIL;
  135. }
  136. /*!--------------------------------------------------------------------------
  137. CAbout::GetStaticFolderImage
  138. MMC calls this to get the bitmap for the snapin's root node
  139. Author:
  140. ---------------------------------------------------------------------------*/
  141. STDMETHODIMP
  142. CAbout::GetStaticFolderImage
  143. (
  144. HBITMAP* hSmallImage,
  145. HBITMAP* hSmallImageOpen,
  146. HBITMAP* hLargeImage,
  147. COLORREF* cLargeMask
  148. )
  149. {
  150. if (NULL == hSmallImage || NULL == hSmallImageOpen || NULL == hLargeImage)
  151. {
  152. return E_POINTER;
  153. }
  154. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  155. if (NULL == m_hSmallImage)
  156. {
  157. m_hSmallImage = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(GetSmallRootId()));
  158. }
  159. *hSmallImage = m_hSmallImage;
  160. if (NULL == m_hSmallImageOpen)
  161. {
  162. m_hSmallImageOpen = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(GetSmallOpenRootId()));
  163. }
  164. *hSmallImageOpen = m_hSmallImageOpen;
  165. if (NULL == m_hLargeImage)
  166. {
  167. m_hLargeImage = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(GetLargeRootId()));
  168. }
  169. *hLargeImage = m_hLargeImage;
  170. *cLargeMask = GetLargeColorMask();
  171. return S_OK;
  172. }