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.

115 lines
2.7 KiB

  1. // PerfSelection.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ShowPerfLib.h"
  5. #include "PerfSelection.h"
  6. #include "ntreg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPerfSelection dialog
  14. CPerfSelection::CPerfSelection(CWnd* pParent /*=NULL*/)
  15. : CDialog(CPerfSelection::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CPerfSelection)
  18. m_strService = _T("");
  19. //}}AFX_DATA_INIT
  20. }
  21. void CPerfSelection::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CPerfSelection)
  25. DDX_Control(pDX, IDC_SERVICE, m_wndService);
  26. // DDX_Control(pDX, IDC_PERFLIST, m_wndPerfList);
  27. DDX_Text(pDX, IDC_SERVICE, m_strService);
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CPerfSelection, CDialog)
  31. //{{AFX_MSG_MAP(CPerfSelection)
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CPerfSelection message handlers
  36. BOOL CPerfSelection::OnInitDialog()
  37. {
  38. CDialog::OnInitDialog();
  39. // TODO: Add extra initialization here
  40. InitList();
  41. m_wndService.SetFocus();
  42. return FALSE; // return TRUE unless you set the focus to a control
  43. // EXCEPTION: OCX Property Pages should return FALSE
  44. }
  45. void CPerfSelection::InitList()
  46. {
  47. CNTRegistry Reg;
  48. WCHAR wszServiceKey[512],
  49. wszPerformanceKey[512];
  50. if ( CNTRegistry::no_error == Reg.Open( HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services" ) )
  51. {
  52. DWORD dwIndex = 0;
  53. // Iterate through the services list
  54. // =================================
  55. DWORD dwBuffSize = 0;
  56. WCHAR* wcsServiceName = NULL;
  57. long lError = CNTRegistry::no_error;
  58. while ( CNTRegistry::no_error == lError )
  59. {
  60. // For each service name, we will check for a performance
  61. // key and if it exists, we will process the library
  62. // ======================================================
  63. lError = Reg.Enum( dwIndex, &wcsServiceName , dwBuffSize );
  64. if ( CNTRegistry::no_error == lError )
  65. {
  66. // Create the perfomance key path
  67. // ==============================
  68. swprintf(wszServiceKey, L"SYSTEM\\CurrentControlSet\\Services\\%s", wcsServiceName);
  69. swprintf(wszPerformanceKey, L"%s\\Performance", wszServiceKey);
  70. CNTRegistry RegSubKey;
  71. // Atempt to open the performance registry key for the service
  72. // ===========================================================
  73. if ( CNTRegistry::no_error == RegSubKey.Open( HKEY_LOCAL_MACHINE, wszPerformanceKey ) )
  74. {
  75. CString str(wcsServiceName);
  76. m_wndPerfList.InsertItem( 1, str );
  77. }
  78. dwIndex++;
  79. }
  80. }
  81. }
  82. }
  83. void CPerfSelection::OnOK()
  84. {
  85. // TODO: Add extra validation here
  86. CDialog::OnOK();
  87. }