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.

207 lines
5.8 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 00
  5. *
  6. * File: archpicker.cpp
  7. *
  8. * Contents: Implementation file for CArchitecturePicker
  9. *
  10. * History: 1-Aug-2000 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. // ArchPicker.cpp : implementation file
  14. //
  15. #include "stdafx.h"
  16. #ifdef _WIN64 // this class is only required on 64-bit platforms
  17. #include "amc.h"
  18. #include "ArchPicker.h"
  19. //#ifdef _DEBUG
  20. //#define new DEBUG_NEW
  21. //#undef THIS_FILE
  22. //static char THIS_FILE[] = __FILE__;
  23. //#endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CArchitecturePicker dialog
  26. /*+-------------------------------------------------------------------------*
  27. * CArchitecturePicker::CArchitecturePicker
  28. *
  29. * Constructs a CArchitecturePicker object.
  30. *--------------------------------------------------------------------------*/
  31. CArchitecturePicker::CArchitecturePicker (
  32. CString strFilename, // I:name of console file
  33. CAvailableSnapinInfo& asi64, // I:available 64-bit snap-ins
  34. CAvailableSnapinInfo& asi32, // I:available 32-bit snap-ins
  35. CWnd* pParent /*=NULL*/) // I:dialog's parent window
  36. : CDialog (CArchitecturePicker::IDD, pParent),
  37. m_asi64 (asi64),
  38. m_asi32 (asi32),
  39. m_strFilename (strFilename),
  40. m_eArch (eArch_64bit)
  41. {
  42. //{{AFX_DATA_INIT(CArchitecturePicker)
  43. //}}AFX_DATA_INIT
  44. ASSERT (!asi64.m_f32Bit);
  45. ASSERT ( asi32.m_f32Bit);
  46. }
  47. void CArchitecturePicker::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CDialog::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(CArchitecturePicker)
  51. DDX_Control(pDX, IDC_SnapinList64, m_wndSnapinList64);
  52. DDX_Control(pDX, IDC_SnapinList32, m_wndSnapinList32);
  53. //}}AFX_DATA_MAP
  54. DDX_Radio(pDX, IDC_64Bit, reinterpret_cast<int&>(m_eArch));
  55. }
  56. BEGIN_MESSAGE_MAP(CArchitecturePicker, CDialog)
  57. //{{AFX_MSG_MAP(CArchitecturePicker)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CArchitecturePicker message handlers
  62. BOOL CArchitecturePicker::OnInitDialog()
  63. {
  64. /*
  65. * these must be consecutive and match the order of radio buttons on
  66. * the dialog
  67. */
  68. ASSERT (eArch_64bit == 0);
  69. ASSERT (eArch_32bit == 1);
  70. ASSERT (GetNextDlgGroupItem(GetDlgItem(IDC_64Bit)) != NULL);
  71. ASSERT (GetNextDlgGroupItem(GetDlgItem(IDC_64Bit))->GetDlgCtrlID() == IDC_32Bit);
  72. /*
  73. * if there are more 32-bit snap-ins than 64-bit snap-ins, default
  74. * to running 32-bit; otherwise, default to running 64-bit
  75. * (do this before calling CDialog::OnInitDialog so the state of
  76. * the radio button will be set correctly when CDialog::OnInitDialog
  77. * calls UpdateData)
  78. */
  79. if (m_asi32.m_vAvailableSnapins.size() > m_asi64.m_vAvailableSnapins.size())
  80. m_eArch = eArch_32bit;
  81. CDialog::OnInitDialog();
  82. /*
  83. * put the filename on the dialog
  84. */
  85. SetDlgItemText (IDC_ConsoleFileName, m_strFilename);
  86. /*
  87. * put formatted messages in the info windows
  88. */
  89. FormatMessage (IDC_SnapinCount64, m_asi64);
  90. FormatMessage (IDC_SnapinCount32, m_asi32);
  91. /*
  92. * populate the lists
  93. */
  94. PopulateList (m_wndSnapinList64, m_asi64);
  95. PopulateList (m_wndSnapinList32, m_asi32);
  96. return TRUE; // return TRUE unless you set the focus to a control
  97. // EXCEPTION: OCX Property Pages should return FALSE
  98. }
  99. /*+-------------------------------------------------------------------------*
  100. * CArchitecturePicker::FormatMessage
  101. *
  102. * Retrieves the format text from the given control, formats the message
  103. * with the information contained in the given CArchitecturePicker, and
  104. * replaces the text in the control with the result.
  105. *--------------------------------------------------------------------------*/
  106. void CArchitecturePicker::FormatMessage (
  107. UINT idControl, /* I:control to update */
  108. CAvailableSnapinInfo& asi) /* I:data to use in formatting */
  109. {
  110. DECLARE_SC (sc, _T("CArchitecturePicker::FormatMessage"));
  111. /*
  112. * get the control
  113. */
  114. CWnd* pwnd = GetDlgItem (idControl);
  115. if (pwnd == NULL)
  116. {
  117. sc.FromLastError();
  118. return;
  119. }
  120. /*
  121. * get the format string from the control
  122. */
  123. CString strFormat;
  124. pwnd->GetWindowText (strFormat);
  125. /*
  126. * format the text
  127. */
  128. CString strText;
  129. strText.FormatMessage (strFormat, asi.m_vAvailableSnapins.size(), asi.m_cTotalSnapins);
  130. /*
  131. * put the text in the window
  132. */
  133. pwnd->SetWindowText (strText);
  134. }
  135. /*+-------------------------------------------------------------------------*
  136. * CArchitecturePicker::PopulateList
  137. *
  138. * Puts the names of each snap-in in asi into the given list control.
  139. *--------------------------------------------------------------------------*/
  140. void CArchitecturePicker::PopulateList (
  141. CListCtrl& wndList, /* I:control to update */
  142. CAvailableSnapinInfo& asi) /* I:data to use in formatting */
  143. {
  144. /*
  145. * put a single, full-width column in the list
  146. */
  147. CRect rect;
  148. wndList.GetClientRect (rect);
  149. int cxColumn = rect.Width() - GetSystemMetrics (SM_CXVSCROLL);
  150. wndList.InsertColumn (0, NULL, LVCFMT_LEFT, cxColumn);
  151. /*
  152. * Give the list the imagelist. The imagelist is owned by the
  153. * CAvailableSnapinInfo, so make sure the list has LVS_SHAREIMAGELISTS
  154. * so it won't delete the image list when it's destroyed.
  155. */
  156. ASSERT (wndList.GetStyle() & LVS_SHAREIMAGELISTS);
  157. wndList.SetImageList (CImageList::FromHandle (asi.m_himl), LVSIL_SMALL);
  158. /*
  159. * put each item in the list
  160. */
  161. std::vector<CBasicSnapinInfo>::iterator it;
  162. for (it = asi.m_vAvailableSnapins.begin();
  163. it != asi.m_vAvailableSnapins.end();
  164. ++it)
  165. {
  166. wndList.InsertItem (-1, it->m_strName.data(), it->m_nImageIndex);
  167. }
  168. }
  169. #endif // _WIN64