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.

249 lines
5.5 KiB

  1. /************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name :
  4. about.cpp
  5. Abstract :
  6. Handles about information for MMC snapin.
  7. Author :
  8. Revision History :
  9. ***********************************************************************/
  10. #include "precomp.h"
  11. CSnapinAbout::CSnapinAbout()
  12. : m_cref(1),
  13. m_hSmallImage( NULL ),
  14. m_hSmallImageOpen( NULL ),
  15. m_hLargeImage( NULL ),
  16. m_hAppIcon( NULL )
  17. {
  18. OBJECT_CREATED
  19. }
  20. CSnapinAbout::~CSnapinAbout()
  21. {
  22. if (m_hSmallImage != NULL)
  23. FreeResource(m_hSmallImage);
  24. if (m_hLargeImage != NULL)
  25. FreeResource(m_hLargeImage);
  26. if (m_hSmallImageOpen != NULL)
  27. FreeResource(m_hSmallImageOpen);
  28. if (m_hAppIcon != NULL)
  29. FreeResource(m_hAppIcon);
  30. m_hSmallImage = NULL;
  31. m_hLargeImage = NULL;
  32. m_hSmallImageOpen = NULL;
  33. m_hAppIcon = NULL;
  34. OBJECT_DESTROYED
  35. }
  36. ///////////////////////
  37. // IUnknown implementation
  38. ///////////////////////
  39. STDMETHODIMP CSnapinAbout::QueryInterface(REFIID riid, LPVOID *ppv)
  40. {
  41. if (!ppv)
  42. return E_FAIL;
  43. *ppv = NULL;
  44. if (IsEqualIID(riid, IID_IUnknown))
  45. *ppv = static_cast<ISnapinAbout *>(this);
  46. else if (IsEqualIID(riid, IID_ISnapinAbout))
  47. *ppv = static_cast<ISnapinAbout *>(this);
  48. if (*ppv)
  49. {
  50. reinterpret_cast<IUnknown *>(*ppv)->AddRef();
  51. return S_OK;
  52. }
  53. return E_NOINTERFACE;
  54. }
  55. STDMETHODIMP_(ULONG) CSnapinAbout::AddRef()
  56. {
  57. return InterlockedIncrement((LONG *)&m_cref);
  58. }
  59. STDMETHODIMP_(ULONG) CSnapinAbout::Release()
  60. {
  61. if (InterlockedDecrement((LONG *)&m_cref) == 0)
  62. {
  63. // we need to decrement our object count in the DLL
  64. delete this;
  65. return 0;
  66. }
  67. return m_cref;
  68. }
  69. ///////////////////////////////
  70. // Interface ISnapinAbout
  71. ///////////////////////////////
  72. STDMETHODIMP CSnapinAbout::GetSnapinDescription(
  73. /* [out] */ LPOLESTR *lpDescription)
  74. {
  75. return LoadStringHelper( lpDescription, IDS_BITSMGR_DESC );
  76. }
  77. STDMETHODIMP CSnapinAbout::GetProvider(
  78. /* [out] */ LPOLESTR *lpName)
  79. {
  80. return LoadStringHelper( lpName, IDS_BITSMGR_PROVIDER );
  81. }
  82. STDMETHODIMP CSnapinAbout::GetSnapinVersion(
  83. /* [out] */ LPOLESTR *lpVersion)
  84. {
  85. return LoadStringHelper( lpVersion, IDS_BITSMGR_VERSION_STR );
  86. }
  87. STDMETHODIMP CSnapinAbout::GetSnapinImage(
  88. /* [out] */ HICON *hAppIcon)
  89. {
  90. if ( m_hAppIcon )
  91. {
  92. *hAppIcon = m_hAppIcon;
  93. return S_OK;
  94. }
  95. *hAppIcon = m_hAppIcon =
  96. LoadIcon(g_hinst, MAKEINTRESOURCE(IDI_BITSMGR));
  97. if ( !m_hAppIcon )
  98. return HRESULT_FROM_WIN32( GetLastError() );
  99. return S_OK;
  100. }
  101. STDMETHODIMP CSnapinAbout::GetStaticFolderImage(
  102. /* [out] */ HBITMAP *hSmallImage,
  103. /* [out] */ HBITMAP *hSmallImageOpen,
  104. /* [out] */ HBITMAP *hLargeImage,
  105. /* [out] */ COLORREF *cMask)
  106. {
  107. HRESULT Hr = S_OK;
  108. if ( m_hSmallImage )
  109. *hSmallImage = m_hSmallImage;
  110. else
  111. {
  112. *hSmallImage = m_hSmallImage =
  113. (HBITMAP)LoadImage(
  114. g_hinst,
  115. MAKEINTRESOURCE(IDB_SMALL),
  116. IMAGE_BITMAP,
  117. 0,
  118. 0,
  119. LR_DEFAULTCOLOR
  120. );
  121. if ( !m_hSmallImage )
  122. {
  123. Hr = HRESULT_FROM_WIN32( GetLastError() );
  124. goto Fail;
  125. }
  126. }
  127. if ( m_hSmallImageOpen )
  128. *hSmallImageOpen = m_hSmallImageOpen;
  129. else
  130. {
  131. *hSmallImageOpen = m_hSmallImageOpen =
  132. (HBITMAP)LoadImage(
  133. g_hinst,
  134. MAKEINTRESOURCE(IDB_SMALL),
  135. IMAGE_BITMAP,
  136. 0,
  137. 0,
  138. LR_DEFAULTCOLOR
  139. );
  140. if ( !m_hSmallImageOpen )
  141. {
  142. Hr = HRESULT_FROM_WIN32( GetLastError() );
  143. goto Fail;
  144. }
  145. }
  146. if ( m_hLargeImage )
  147. *hLargeImage = m_hLargeImage;
  148. else
  149. {
  150. *hLargeImage = m_hLargeImage =
  151. (HBITMAP)LoadImage(
  152. g_hinst,
  153. MAKEINTRESOURCE(IDB_SMALL),
  154. IMAGE_BITMAP,
  155. 0,
  156. 0,
  157. LR_DEFAULTCOLOR
  158. );
  159. if ( !m_hLargeImage )
  160. {
  161. Hr = HRESULT_FROM_WIN32( GetLastError() );
  162. goto Fail;
  163. }
  164. }
  165. *cMask = RGB(255,0,255); // purple
  166. return S_OK;
  167. Fail:
  168. *hSmallImage = *hSmallImageOpen = *hLargeImage = NULL;
  169. memset( cMask, 0, sizeof(COLORREF) );
  170. return Hr;
  171. }
  172. HRESULT
  173. CSnapinAbout::LoadStringHelper(
  174. LPOLESTR *lpDest,
  175. UINT Id )
  176. {
  177. *lpDest = (LPOLESTR)CoTaskMemAlloc( sizeof(WCHAR) * MAX_PATH );
  178. if ( !lpDest )
  179. return E_OUTOFMEMORY;
  180. int RetVal =
  181. LoadString( g_hinst, Id, *lpDest, MAX_PATH - 1 );
  182. if ( !RetVal )
  183. {
  184. HRESULT Hr = HRESULT_FROM_WIN32( GetLastError() );
  185. CoTaskMemFree( lpDest );
  186. *lpDest = NULL;
  187. return Hr;
  188. }
  189. return S_OK;
  190. }