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.

295 lines
7.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: about.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "about.h"
  12. #include "bitmap.h"
  13. #define EDIT_CONTROL_CRLF _T("\r\r\n")
  14. //
  15. // This file implements the About Properties used by the snap-in manager
  16. //
  17. CSnapinAbout::CSnapinAbout()
  18. {
  19. TRACE_METHOD(CSnapinAbout, CSnapinAbout);
  20. CommonContruct();
  21. }
  22. void CSnapinAbout::CommonContruct()
  23. {
  24. m_bBasicInfo = FALSE;
  25. m_bFullInfo = FALSE;
  26. m_cMask = RGB(0,0,0);
  27. m_hrObjectStatus = S_OK;
  28. }
  29. BOOL CSnapinAbout::GetInformation(CLSID& clsid, int nType)
  30. {
  31. TRACE_METHOD(CSnapinAbout, GetInformation);
  32. if (m_bFullInfo == TRUE || m_bBasicInfo == TRUE)
  33. {
  34. TRACE(_T("Destroying old Snapin information\n"));
  35. // Preserve the snapin name, it can't be reloaded from
  36. // the snapin ISnapinAbout interface
  37. LPOLESTR strTemp = m_lpszSnapinName.Detach();
  38. CSnapinAbout::~CSnapinAbout();
  39. m_lpszSnapinName.Attach(strTemp);
  40. }
  41. m_bFullInfo = m_bBasicInfo = FALSE;
  42. // Create the interface and get the snap-in information
  43. ISnapinAboutPtr spAboutInfo;
  44. m_hrObjectStatus = spAboutInfo.CreateInstance(clsid, NULL, MMC_CLSCTX_INPROC);
  45. if (FAILED(m_hrObjectStatus))
  46. return FALSE;
  47. // Basic info (required to display snapin node)
  48. HBITMAP hbmSmallImage;
  49. HBITMAP hbmSmallImageOpen;
  50. HBITMAP hbmLargeImage;
  51. if (SUCCEEDED(spAboutInfo->GetStaticFolderImage (&hbmSmallImage,
  52. &hbmSmallImageOpen,
  53. &hbmLargeImage,
  54. &m_cMask)))
  55. {
  56. /*
  57. * Bug 249817: The bitmaps are out parameters, so the caller (MMC)
  58. * should own them and be responsible for destroying them.
  59. * Unfortunately, the docs for ISnapinAbout::GetStaticFolderImage
  60. * specifically instruct the snap-in to destroy them when the
  61. * ISnapinAbout interface is released. We have to make copies instead.
  62. */
  63. m_SmallImage = CopyBitmap (hbmSmallImage);
  64. m_SmallImageOpen = CopyBitmap (hbmSmallImageOpen);
  65. m_LargeImage = CopyBitmap (hbmLargeImage);
  66. }
  67. m_bBasicInfo = TRUE;
  68. if (nType == BASIC_INFO)
  69. return TRUE;
  70. // Full information (required for About box)
  71. HICON hTemp;
  72. /*
  73. * Bug 249817: The icon is an out parameter, so the caller (MMC)
  74. * should own it and be responsible for destroying it.
  75. * Unfortunately, the docs for ISnapinAbout::GetSnapinImage
  76. * specifically instruct the snap-in to destroy it when the
  77. * ISnapinAbout interface is released. We have to make a copy instead.
  78. */
  79. if (SUCCEEDED(spAboutInfo->GetSnapinImage(&hTemp)))
  80. m_AppIcon.Attach(CopyIcon(hTemp));
  81. LPOLESTR strTemp;
  82. if (SUCCEEDED(spAboutInfo->GetSnapinDescription(&strTemp)))
  83. m_lpszDescription.Attach(strTemp);
  84. if (SUCCEEDED(spAboutInfo->GetProvider(&strTemp)))
  85. m_lpszCompanyName.Attach(strTemp);
  86. if (SUCCEEDED(spAboutInfo->GetSnapinVersion(&strTemp)))
  87. m_lpszVersion.Attach(strTemp);
  88. m_bFullInfo = TRUE;
  89. return TRUE;
  90. }
  91. void CSnapinAbout::ShowAboutBox()
  92. {
  93. TRACE_METHOD(CSnapinAbout, Show);
  94. CSnapinAboutDialog dlg(this);
  95. dlg.DoModal();
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CSnapinAboutPage message handlers
  99. LRESULT CSnapinAboutDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  100. {
  101. // hook up controls
  102. DECLARE_SC(sc, TEXT("CSnapinAboutDialog::OnInitDialog"));
  103. sc = ScCheckPointers(m_pAboutInfo, E_UNEXPECTED);
  104. if (sc)
  105. return TRUE;
  106. // Title should be set "About <SnapinName>"
  107. tstring szTitle;
  108. bool bRet = szTitle.LoadString(GetStringModule(), IDS_ABOUT);
  109. if (!bRet)
  110. return TRUE;
  111. USES_CONVERSION;
  112. LPCOLESTR lpszSnapinName = m_pAboutInfo->GetSnapinName();
  113. if (lpszSnapinName)
  114. szTitle += OLE2CT(lpszSnapinName);
  115. else
  116. {
  117. tstring szSnapin;
  118. bRet = szSnapin.LoadString(GetStringModule(), IDS_SNAPINSTR);
  119. if (!bRet)
  120. return TRUE;
  121. szTitle += szSnapin;
  122. }
  123. SetWindowText(szTitle.data());
  124. HWND hwndSnapinInfo = ::GetDlgItem(*this, IDC_SNAPIN_INFO);
  125. sc = ScCheckPointers(hwndSnapinInfo, E_UNEXPECTED);
  126. if (sc)
  127. return TRUE;
  128. m_SnapinInfo.Attach(hwndSnapinInfo);
  129. if (lpszSnapinName)
  130. {
  131. m_SnapinInfo.AppendText(OLE2CT(lpszSnapinName));
  132. m_SnapinInfo.AppendText(EDIT_CONTROL_CRLF);
  133. }
  134. LPCOLESTR lpszCompanyName = m_pAboutInfo->GetCompanyName();
  135. if (lpszCompanyName)
  136. {
  137. m_SnapinInfo.AppendText(OLE2CT(lpszCompanyName));
  138. m_SnapinInfo.AppendText(EDIT_CONTROL_CRLF);
  139. }
  140. LPCOLESTR lpszVersion = m_pAboutInfo->GetVersion();
  141. if (lpszVersion)
  142. {
  143. tstring szVersion;
  144. bRet = szVersion.LoadString(GetStringModule(), IDS_VERSION);
  145. if (!bRet)
  146. return TRUE;
  147. m_SnapinInfo.AppendText(szVersion.data());
  148. m_SnapinInfo.AppendText(OLE2CT(lpszVersion));
  149. }
  150. HWND hwndSnapinDesc = ::GetDlgItem(*this, IDC_SNAPIN_DESC);
  151. sc = ScCheckPointers(hwndSnapinDesc, E_UNEXPECTED);
  152. if (sc)
  153. return TRUE;
  154. m_SnapinDesc.Attach(hwndSnapinDesc);
  155. LPCOLESTR lpszDescription = m_pAboutInfo->GetDescription();
  156. sc = ScSetDescriptionUIText(m_SnapinDesc, lpszDescription ? OLE2CT(lpszDescription) : _T(""));
  157. if (sc)
  158. return TRUE;
  159. // App icon
  160. HICON hAppIcon = m_pAboutInfo->GetSnapinIcon();
  161. if (hAppIcon)
  162. {
  163. HWND const icon = ::GetDlgItem(*this, IDC_APPICON);
  164. ASSERT(icon != NULL);
  165. m_hIcon.Attach(icon);
  166. m_hIcon.SetIcon(hAppIcon);
  167. }
  168. return TRUE;
  169. }
  170. LRESULT
  171. CSnapinAboutDialog::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  172. {
  173. EndDialog(IDOK);
  174. return TRUE;
  175. }
  176. LRESULT
  177. CSnapinAboutDialog::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  178. {
  179. EndDialog(IDCANCEL);
  180. return FALSE;
  181. }
  182. //+-------------------------------------------------------------------
  183. //
  184. // Member: ScSetDescriptionUIText
  185. //
  186. // Synopsis: Given a edit control window & description text. Insert
  187. // the text into the control and enable scrollbar if needed.
  188. //
  189. // Arguments: [hwndSnapinDescEdit] - The edit control window handle.
  190. // [lpszDescription] - The description text (cant be NULL).
  191. //
  192. // Returns: SC
  193. //
  194. //--------------------------------------------------------------------
  195. SC ScSetDescriptionUIText(HWND hwndSnapinDescEdit, LPCTSTR lpszDescription)
  196. {
  197. DECLARE_SC(sc, TEXT("ScSetDescriptionUIText"));
  198. sc = ScCheckPointers(hwndSnapinDescEdit, lpszDescription);
  199. if (sc)
  200. return sc;
  201. // 1. Attach the window to WTL::CEdit object.
  202. WTL::CEdit wndsnapinDesc(hwndSnapinDescEdit);
  203. // 2. Insert the text into the window.
  204. wndsnapinDesc.SetWindowText(lpszDescription);
  205. /*
  206. * 3. The description control may need scroll bar.
  207. * This is determined below, if ( (# of lines * height of one line) > rectangle-height).
  208. */
  209. // 3a) turn-off scroll & do the calculation, so that scroll-bar width does not
  210. // modify linecount below.
  211. wndsnapinDesc.ShowScrollBar(SB_VERT, FALSE);
  212. WTL::CDC dc(wndsnapinDesc.GetWindowDC());
  213. if (dc.IsNull())
  214. return (sc = E_UNEXPECTED);
  215. TEXTMETRIC tm;
  216. // 3b) Calculate height of a single line.
  217. HFONT hOldFont = dc.SelectFont(wndsnapinDesc.GetFont());
  218. dc.GetTextMetrics(&tm);
  219. int cyLineHeight = tm.tmHeight + tm.tmExternalLeading;
  220. // 3c) Calculate edit box dimensions in logical units.
  221. WTL::CRect rect;
  222. wndsnapinDesc.GetRect(&rect);
  223. dc.DPtoLP(&rect);
  224. int nLines = wndsnapinDesc.GetLineCount();
  225. // 3d) If the total text height exceeds edit box height so turn on scroll.
  226. if ( (nLines * cyLineHeight) > rect.Height())
  227. wndsnapinDesc.ShowScrollBar(SB_VERT, TRUE);
  228. dc.SelectFont(hOldFont);
  229. wndsnapinDesc.SetSel(0, 0);
  230. return sc;
  231. }