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.

176 lines
4.4 KiB

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