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.

157 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: stdabout.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. HRESULT
  12. HrLoadOleString(
  13. UINT uStringId, // IN: String Id to load from the resource
  14. OUT LPOLESTR * ppaszOleString) // OUT: Pointer to pointer to allocated OLE string
  15. {
  16. if (ppaszOleString == NULL)
  17. {
  18. TRACE0("HrLoadOleString() - ppaszOleString is NULL.\n");
  19. return E_POINTER;
  20. }
  21. CString strT; // Temporary string
  22. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Needed for LoadString()
  23. VERIFY( strT.LoadString(uStringId) );
  24. *ppaszOleString = reinterpret_cast<LPOLESTR>
  25. (CoTaskMemAlloc((strT.GetLength() + 1)* sizeof(wchar_t)));
  26. if (*ppaszOleString == NULL)
  27. return E_OUTOFMEMORY;
  28. USES_CONVERSION;
  29. wcscpy(OUT *ppaszOleString, T2OLE((LPTSTR)(LPCTSTR)strT));
  30. return S_OK;
  31. } // HrLoadOleString()
  32. CSnapinAbout::CSnapinAbout(UINT uIdStrDestription,
  33. UINT uIdIconImage, // Resource Id for the icon/image of the snapin
  34. UINT uIdBitmapSmallImage,
  35. UINT uIdBitmapSmallImageOpen,
  36. UINT uIdBitmapLargeImage,
  37. COLORREF crImageMask):
  38. m_uIdStrDestription(uIdStrDestription),
  39. m_uIdIconImage(uIdIconImage),
  40. m_uIdBitmapSmallImage(uIdBitmapSmallImage),
  41. m_uIdBitmapSmallImageOpen(uIdBitmapSmallImageOpen),
  42. m_uIdBitmapLargeImage(uIdBitmapLargeImage),
  43. m_crImageMask(crImageMask),
  44. m_hSmallImage(0),
  45. m_hSmallImageOpen(0),
  46. m_hLargeImage(0)
  47. {
  48. }
  49. CSnapinAbout::~CSnapinAbout()
  50. {
  51. if ( m_hSmallImage )
  52. ::DeleteObject (m_hSmallImage);
  53. if ( m_hSmallImageOpen )
  54. ::DeleteObject (m_hSmallImageOpen);
  55. if ( m_hLargeImage )
  56. ::DeleteObject (m_hLargeImage);
  57. }
  58. STDMETHODIMP CSnapinAbout::GetSnapinDescription(OUT LPOLESTR __RPC_FAR *lpDescription)
  59. {
  60. return HrLoadOleString(m_uIdStrDestription, OUT lpDescription);
  61. }
  62. STDMETHODIMP CSnapinAbout::GetProvider(OUT LPOLESTR __RPC_FAR *lpName)
  63. {
  64. if (lpName == NULL)
  65. {
  66. TRACE0("CSnapinAbout::GetProvider() - lpName is NULL.\n");
  67. return E_POINTER;
  68. }
  69. *lpName = reinterpret_cast<LPOLESTR>
  70. (CoTaskMemAlloc((wcslen(STR_SNAPIN_COMPANY) + 1) * sizeof(wchar_t)));
  71. if (*lpName == NULL)
  72. return E_OUTOFMEMORY;
  73. USES_CONVERSION;
  74. wcscpy(*lpName, T2OLE(STR_SNAPIN_COMPANY));
  75. return S_OK;
  76. }
  77. STDMETHODIMP CSnapinAbout::GetSnapinVersion(OUT LPOLESTR __RPC_FAR *lpVersion)
  78. {
  79. if (lpVersion == NULL)
  80. {
  81. TRACE0("CSnapinAbout::GetSnapinVersion() - lpVersion is NULL.\n");
  82. return E_POINTER;
  83. }
  84. CString str;
  85. str.Format(TEXT("%hs"), STR_SNAPIN_VERSION); // this is a concatenation of ANSI strings, hence this conversion to UNICODE.
  86. *lpVersion = reinterpret_cast<LPOLESTR>
  87. (CoTaskMemAlloc((str.GetLength() + 1) * sizeof(wchar_t)));
  88. if (*lpVersion == NULL)
  89. return E_OUTOFMEMORY;
  90. USES_CONVERSION;
  91. wcscpy(*lpVersion, T2OLE((LPTSTR)(LPCTSTR)str));
  92. return S_OK;
  93. }
  94. STDMETHODIMP CSnapinAbout::GetSnapinImage(OUT HICON __RPC_FAR *hAppIcon)
  95. {
  96. if (hAppIcon == NULL)
  97. return E_POINTER;
  98. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Required for AfxGetInstanceHandle()
  99. *hAppIcon = ::LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(m_uIdIconImage));
  100. if (*hAppIcon == NULL)
  101. {
  102. ASSERT(FALSE && "Unable to load icon");
  103. return E_FAIL;
  104. }
  105. return S_OK;
  106. }
  107. STDMETHODIMP CSnapinAbout::GetStaticFolderImage(
  108. OUT HBITMAP __RPC_FAR *hSmallImage,
  109. OUT HBITMAP __RPC_FAR *hSmallImageOpen,
  110. OUT HBITMAP __RPC_FAR *hLargeImage,
  111. OUT COLORREF __RPC_FAR *crMask)
  112. {
  113. ASSERT(hSmallImage != NULL);
  114. ASSERT(hSmallImageOpen != NULL);
  115. ASSERT(hLargeImage != NULL);
  116. ASSERT(crMask != NULL);
  117. AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Required for AfxGetInstanceHandle()
  118. HINSTANCE hInstance = AfxGetInstanceHandle();
  119. if ( !m_hSmallImage )
  120. m_hSmallImage = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapSmallImage));
  121. if ( !m_hSmallImageOpen )
  122. m_hSmallImageOpen = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapSmallImageOpen));
  123. if ( !m_hLargeImage )
  124. m_hLargeImage = ::LoadBitmap(hInstance, MAKEINTRESOURCE(m_uIdBitmapLargeImage));
  125. *hSmallImage = m_hSmallImage;
  126. *hSmallImageOpen = m_hSmallImageOpen;
  127. *hLargeImage = m_hLargeImage;
  128. *crMask = m_crImageMask;
  129. #ifdef _DEBUG
  130. if (NULL == *hSmallImage || NULL == *hSmallImageOpen || NULL == *hLargeImage)
  131. {
  132. TRACE0("WRN: CSnapinAbout::GetStaticFolderImage() - Unable to load all the bitmaps.\n");
  133. return E_FAIL;
  134. }
  135. #endif
  136. return S_OK;
  137. }