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.

1363 lines
42 KiB

  1. // exctrdlg.cpp : implementation file
  2. //
  3. #ifndef UNICODE
  4. #define UNICODE 1
  5. #endif
  6. #ifndef _UNICODE
  7. #define _UNICODE 1
  8. #endif
  9. #include "stdafx.h"
  10. #include "exctrlst.h"
  11. #include "exctrdlg.h"
  12. #include "tchar.h"
  13. // string constants
  14. // displayed strings
  15. const TCHAR cszNotFound[] = {TEXT("Not Found")};
  16. const TCHAR cszNA[] = {TEXT("N/A")};
  17. // strings that are not displayed
  18. const WCHAR cszServiceKeyName[] = L"SYSTEM\\CurrentControlSet\\Services";
  19. const WCHAR cszNamesKey[] = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib";
  20. // Performance subkey registry value names
  21. const WCHAR cszDisablePerformanceCounters[] = {L"Disable Performance Counters"};
  22. const TCHAR cszDoubleBackslash[] = {TEXT("\\\\")};
  23. const TCHAR cszSpace[] = {TEXT(" ")};
  24. const TCHAR cszSplat[] = {TEXT("*")};
  25. const TCHAR cszServIdFmt[] = {TEXT("%d %s")};
  26. const TCHAR cszOpen[] = {TEXT("Open")};
  27. const TCHAR cszCollect[] = {TEXT("Collect")};
  28. const TCHAR cszClose[] = {TEXT("Close")};
  29. const TCHAR cszIdFmt[] = {TEXT("0x%8.8x (%d) %s")};
  30. const TCHAR cszSortIdFmt[] = {TEXT("0x%8.8x\t%s")};
  31. const TCHAR cszTab[] = {TEXT("\t")};
  32. const TCHAR cszFirstCounter[] = {TEXT("First Counter")};
  33. const TCHAR cszLastCounter[] = {TEXT("Last Counter")};
  34. const TCHAR cszFirstHelp[] = {TEXT("First Help")};
  35. const TCHAR cszLastHelp[] = {TEXT("Last Help")};
  36. const TCHAR cszLibrary[] = {TEXT("Library")};
  37. const TCHAR cszPerformance[] = {TEXT("\\Performance")};
  38. const TCHAR cszSlash[] = {TEXT("\\")};
  39. const WCHAR cszVersionName[] = {L"Version"};
  40. const WCHAR cszCounterName[] = {L"Counter "};
  41. const WCHAR cszHelpName[] = {L"Explain "};
  42. const WCHAR cszCounters[] = {L"Counters"};
  43. const TCHAR cszHelp[] = {TEXT("Help")};
  44. // Perflib registry values
  45. const WCHAR cszDefaultLangId[] = L"009";
  46. const WCHAR cszConfigurationFlags[] = L"Configuration Flags";
  47. const WCHAR cszEventLogLevel[] = L"EventLogLevel";
  48. const WCHAR cszExtCounterTestLevel[] = L"ExtCounterTestLevel";
  49. const WCHAR cszFailureLimit[] = L"Error Count Limit";
  50. #ifdef _DEBUG
  51. #undef THIS_FILE
  52. char BASED_CODE THIS_FILE[] = __FILE__;
  53. #endif
  54. BOOL CExctrlstDlg::IndexHasString (
  55. DWORD dwIndex
  56. )
  57. {
  58. if ((dwIndex <= dwLastElement) && (pNameTable != NULL)) {
  59. if (pNameTable[dwIndex] != NULL) {
  60. return TRUE;
  61. } else {
  62. return FALSE;
  63. }
  64. } else {
  65. return FALSE;
  66. }
  67. }
  68. LPWSTR
  69. *BuildNameTable(
  70. LPCWSTR szMachineName,
  71. LPCWSTR lpszLangIdArg, // unicode value of Language subkey
  72. PDWORD pdwLastItem, // size of array in elements
  73. PDWORD pdwIdArray // array for index ID's
  74. )
  75. /*++
  76. BuildNameTable
  77. Arguments:
  78. hKeyRegistry
  79. Handle to an open registry (this can be local or remote.) and
  80. is the value returned by RegConnectRegistry or a default key.
  81. lpszLangId
  82. The unicode id of the language to look up. (default is 409)
  83. Return Value:
  84. pointer to an allocated table. (the caller must MemoryFree it when finished!)
  85. the table is an array of pointers to zero terminated strings. NULL is
  86. returned if an error occured.
  87. --*/
  88. {
  89. HKEY hKeyRegistry; // handle to registry db with counter names
  90. LPWSTR *lpReturnValue;
  91. LPCWSTR lpszLangId;
  92. LPWSTR *lpCounterId;
  93. LPWSTR lpCounterNames;
  94. LPWSTR lpHelpText;
  95. LPWSTR lpThisName;
  96. LONG lWin32Status;
  97. DWORD dwLastError;
  98. DWORD dwValueType;
  99. DWORD dwArraySize;
  100. DWORD dwBufferSize;
  101. DWORD dwCounterSize;
  102. DWORD dwHelpSize;
  103. DWORD dwThisCounter;
  104. DWORD dwSystemVersion;
  105. DWORD dwLastId;
  106. DWORD dwLastHelpId;
  107. DWORD dwLastCounterIdUsed;
  108. DWORD dwLastHelpIdUsed;
  109. HKEY hKeyValue;
  110. HKEY hKeyNames;
  111. LPWSTR lpValueNameString;
  112. WCHAR CounterNameBuffer [50];
  113. WCHAR HelpNameBuffer [50];
  114. hKeyRegistry = NULL;
  115. if (szMachineName != NULL) {
  116. lWin32Status = RegConnectRegistryW (szMachineName,
  117. HKEY_LOCAL_MACHINE,
  118. &hKeyRegistry);
  119. } else {
  120. lWin32Status = ERROR_SUCCESS;
  121. hKeyRegistry = HKEY_LOCAL_MACHINE;
  122. }
  123. lpValueNameString = NULL; //initialize to NULL
  124. lpReturnValue = NULL;
  125. hKeyValue = NULL;
  126. hKeyNames = NULL;
  127. // check for null arguments and insert defaults if necessary
  128. if (!lpszLangIdArg) {
  129. lpszLangId = cszDefaultLangId;
  130. } else {
  131. lpszLangId = lpszLangIdArg;
  132. }
  133. // open registry to get number of items for computing array size
  134. if (lWin32Status == ERROR_SUCCESS) {
  135. lWin32Status = RegOpenKeyEx (
  136. hKeyRegistry,
  137. cszNamesKey,
  138. RESERVED,
  139. KEY_READ,
  140. &hKeyValue);
  141. }
  142. if (lWin32Status != ERROR_SUCCESS) {
  143. goto BNT_BAILOUT;
  144. }
  145. // get number of items
  146. dwBufferSize = sizeof (dwLastHelpId);
  147. lWin32Status = RegQueryValueEx (
  148. hKeyValue,
  149. cszLastHelp,
  150. RESERVED,
  151. &dwValueType,
  152. (LPBYTE)&dwLastHelpId,
  153. &dwBufferSize);
  154. if ((lWin32Status != ERROR_SUCCESS) || (dwValueType != REG_DWORD)) {
  155. goto BNT_BAILOUT;
  156. }
  157. pdwIdArray[2] = dwLastHelpId;
  158. // get number of items
  159. dwBufferSize = sizeof (dwLastId);
  160. lWin32Status = RegQueryValueEx (
  161. hKeyValue,
  162. cszLastCounter,
  163. RESERVED,
  164. &dwValueType,
  165. (LPBYTE)&dwLastId,
  166. &dwBufferSize);
  167. if ((lWin32Status != ERROR_SUCCESS) || (dwValueType != REG_DWORD)) {
  168. goto BNT_BAILOUT;
  169. }
  170. pdwIdArray[0] = dwLastId;
  171. if (dwLastId < dwLastHelpId)
  172. dwLastId = dwLastHelpId;
  173. dwArraySize = dwLastId * sizeof(LPWSTR);
  174. // get Perflib system version
  175. dwBufferSize = sizeof (dwSystemVersion);
  176. lWin32Status = RegQueryValueEx (
  177. hKeyValue,
  178. cszVersionName,
  179. RESERVED,
  180. &dwValueType,
  181. (LPBYTE)&dwSystemVersion,
  182. &dwBufferSize);
  183. if ((lWin32Status != ERROR_SUCCESS) || (dwValueType != REG_DWORD)) {
  184. dwSystemVersion = OLD_VERSION;
  185. // reset the error status
  186. lWin32Status = ERROR_SUCCESS;
  187. }
  188. if (dwSystemVersion == OLD_VERSION) {
  189. // get names from registry
  190. lpValueNameString = (LPWSTR)HeapAlloc (GetProcessHeap(), 0,
  191. lstrlen(cszNamesKey) * sizeof (WCHAR) +
  192. lstrlen(cszSlash) * sizeof (WCHAR) +
  193. lstrlen(lpszLangId) * sizeof (WCHAR) +
  194. sizeof (UNICODE_NULL));
  195. if (!lpValueNameString) goto BNT_BAILOUT;
  196. lstrcpy (lpValueNameString, cszNamesKey);
  197. lstrcat (lpValueNameString, cszSlash);
  198. lstrcat (lpValueNameString, lpszLangId);
  199. lWin32Status = RegOpenKeyEx (
  200. hKeyRegistry,
  201. lpValueNameString,
  202. RESERVED,
  203. KEY_READ,
  204. &hKeyNames);
  205. } else {
  206. if (szMachineName[0] == 0) {
  207. hKeyNames = HKEY_PERFORMANCE_DATA;
  208. } else {
  209. lWin32Status = RegConnectRegistry (szMachineName,
  210. HKEY_PERFORMANCE_DATA,
  211. &hKeyNames);
  212. }
  213. lstrcpy (CounterNameBuffer, cszCounterName);
  214. lstrcat (CounterNameBuffer, lpszLangId);
  215. lstrcpy (HelpNameBuffer, cszHelpName);
  216. lstrcat (HelpNameBuffer, lpszLangId);
  217. }
  218. // get size of counter names and add that to the arrays
  219. if (lWin32Status != ERROR_SUCCESS) {
  220. goto BNT_BAILOUT;
  221. }
  222. dwBufferSize = 0;
  223. lWin32Status = RegQueryValueEx (
  224. hKeyNames,
  225. dwSystemVersion == (DWORD)OLD_VERSION ? cszCounters : CounterNameBuffer,
  226. RESERVED,
  227. &dwValueType,
  228. NULL,
  229. &dwBufferSize);
  230. if (lWin32Status != ERROR_SUCCESS) {
  231. goto BNT_BAILOUT;
  232. }
  233. dwCounterSize = dwBufferSize;
  234. // get size of counter names and add that to the arrays
  235. if (lWin32Status != ERROR_SUCCESS) goto BNT_BAILOUT;
  236. dwBufferSize = 0;
  237. lWin32Status = RegQueryValueEx (
  238. hKeyNames,
  239. dwSystemVersion == (DWORD)OLD_VERSION ? cszHelp : HelpNameBuffer,
  240. RESERVED,
  241. &dwValueType,
  242. NULL,
  243. &dwBufferSize);
  244. if (lWin32Status != ERROR_SUCCESS) {
  245. goto BNT_BAILOUT;
  246. }
  247. dwHelpSize = dwBufferSize;
  248. lpReturnValue = (LPWSTR *)HeapAlloc (GetProcessHeap(), 0,dwArraySize + dwCounterSize + dwHelpSize);
  249. if (!lpReturnValue) {
  250. goto BNT_BAILOUT;
  251. }
  252. // initialize pointers into buffer
  253. lpCounterId = lpReturnValue;
  254. lpCounterNames = (LPWSTR)((LPBYTE)lpCounterId + dwArraySize);
  255. lpHelpText = (LPWSTR)((LPBYTE)lpCounterNames + dwCounterSize);
  256. // read counters into memory
  257. dwBufferSize = dwCounterSize;
  258. lWin32Status = RegQueryValueExW (
  259. hKeyNames,
  260. dwSystemVersion == OLD_VERSION ? cszCounters : CounterNameBuffer,
  261. RESERVED,
  262. &dwValueType,
  263. (LPBYTE)lpCounterNames,
  264. &dwBufferSize);
  265. if (!lpReturnValue) {
  266. goto BNT_BAILOUT;
  267. }
  268. dwBufferSize = dwHelpSize;
  269. lWin32Status = RegQueryValueExW (
  270. hKeyNames,
  271. dwSystemVersion == OLD_VERSION ? cszHelp : HelpNameBuffer,
  272. RESERVED,
  273. &dwValueType,
  274. (LPBYTE)lpHelpText,
  275. &dwBufferSize);
  276. if (!lpReturnValue) {
  277. goto BNT_BAILOUT;
  278. }
  279. dwLastCounterIdUsed = 0;
  280. dwLastHelpIdUsed = 0;
  281. // load counter array items
  282. for (lpThisName = lpCounterNames;
  283. *lpThisName;
  284. lpThisName += (lstrlen(lpThisName)+1) ) {
  285. // first string should be an integer (in decimal unicode digits)
  286. dwThisCounter = wcstoul (lpThisName, NULL, 10);
  287. if (dwThisCounter == 0) {
  288. goto BNT_BAILOUT; // bad entry
  289. }
  290. // point to corresponding counter name
  291. lpThisName += (lstrlen(lpThisName)+1);
  292. // and load array element;
  293. lpCounterId[dwThisCounter] = lpThisName;
  294. if (dwThisCounter > dwLastCounterIdUsed) dwLastCounterIdUsed = dwThisCounter;
  295. }
  296. pdwIdArray[1] = dwLastCounterIdUsed;
  297. for (lpThisName = lpHelpText;
  298. *lpThisName;
  299. lpThisName += (lstrlen(lpThisName)+1) ) {
  300. // first string should be an integer (in decimal unicode digits)
  301. dwThisCounter = wcstoul (lpThisName, NULL, 10);
  302. if (dwThisCounter == 0) {
  303. goto BNT_BAILOUT; // bad entry
  304. }
  305. // point to corresponding counter name
  306. lpThisName += (lstrlen(lpThisName)+1);
  307. // and load array element;
  308. lpCounterId[dwThisCounter] = lpThisName;
  309. if (dwThisCounter > dwLastHelpIdUsed) dwLastHelpIdUsed= dwThisCounter;
  310. }
  311. pdwIdArray[3] = dwLastHelpIdUsed;
  312. dwLastId = dwLastHelpIdUsed;
  313. if (dwLastId < dwLastCounterIdUsed) dwLastId = dwLastCounterIdUsed;
  314. if (pdwLastItem) *pdwLastItem = dwLastId;
  315. HeapFree (GetProcessHeap(), 0, (LPVOID)lpValueNameString);
  316. RegCloseKey (hKeyValue);
  317. // if (dwSystemVersion == OLD_VERSION)
  318. RegCloseKey (hKeyNames);
  319. if ((hKeyRegistry != HKEY_LOCAL_MACHINE) &&
  320. (hKeyRegistry != NULL)) {
  321. RegCloseKey(hKeyRegistry);
  322. }
  323. return lpReturnValue;
  324. BNT_BAILOUT:
  325. if (lWin32Status != ERROR_SUCCESS) {
  326. dwLastError = GetLastError();
  327. }
  328. if (lpValueNameString) {
  329. HeapFree (GetProcessHeap(), 0, (LPVOID)lpValueNameString);
  330. }
  331. if (lpReturnValue) {
  332. HeapFree (GetProcessHeap(), 0, (LPVOID)lpReturnValue);
  333. }
  334. if ((hKeyValue != NULL) && (hKeyValue != INVALID_HANDLE_VALUE)) {
  335. RegCloseKey (hKeyValue);
  336. }
  337. // if (dwSystemVersion == OLD_VERSION &&
  338. // hKeyNames)
  339. if ((hKeyNames != NULL) && (hKeyNames != INVALID_HANDLE_VALUE)) {
  340. RegCloseKey (hKeyNames);
  341. }
  342. if ((hKeyRegistry != HKEY_LOCAL_MACHINE) &&
  343. (hKeyRegistry != NULL)) {
  344. RegCloseKey(hKeyRegistry);
  345. }
  346. return NULL;
  347. }
  348. BOOL
  349. IsMsObject(CString *pLibraryName)
  350. {
  351. CString LocalLibraryName;
  352. LocalLibraryName = *pLibraryName;
  353. LocalLibraryName.MakeLower();
  354. // for now this just compares known DLL names. valid as of
  355. // NT v4.0
  356. if (LocalLibraryName.Find((LPCWSTR)L"perfctrs.dll") >= 0) return TRUE;
  357. if (LocalLibraryName.Find((LPCWSTR)L"ftpctrs.dll") >= 0) return TRUE;
  358. if (LocalLibraryName.Find((LPCWSTR)L"rasctrs.dll") >= 0) return TRUE;
  359. if (LocalLibraryName.Find((LPCWSTR)L"winsctrs.dll") >= 0) return TRUE;
  360. if (LocalLibraryName.Find((LPCWSTR)L"sfmctrs.dll") >= 0) return TRUE;
  361. if (LocalLibraryName.Find((LPCWSTR)L"atkctrs.dll") >= 0) return TRUE;
  362. if (LocalLibraryName.Find((LPCWSTR)L"bhmon.dll") >= 0) return TRUE;
  363. if (LocalLibraryName.Find((LPCWSTR)L"tapictrs.dll") >= 0) return TRUE;
  364. // NT v5.0
  365. if (LocalLibraryName.Find((LPCWSTR)L"perfdisk.dll") >= 0) return TRUE;
  366. if (LocalLibraryName.Find((LPCWSTR)L"perfos.dll") >= 0) return TRUE;
  367. if (LocalLibraryName.Find((LPCWSTR)L"perfproc.dll") >= 0) return TRUE;
  368. if (LocalLibraryName.Find((LPCWSTR)L"perfnet.dll") >= 0) return TRUE;
  369. if (LocalLibraryName.Find((LPCWSTR)L"winspool.drv") >= 0) return TRUE;
  370. if (LocalLibraryName.Find((LPCWSTR)L"tapiperf.dll") >= 0) return TRUE;
  371. return FALSE;
  372. }
  373. /////////////////////////////////////////////////////////////////////////////
  374. // CExctrlstDlg dialog
  375. CExctrlstDlg::CExctrlstDlg(CWnd* pParent /*=NULL*/)
  376. : CDialog(CExctrlstDlg::IDD, pParent)
  377. {
  378. //{{AFX_DATA_INIT(CExctrlstDlg)
  379. // NOTE: the ClassWizard will add member initialization here
  380. //}}AFX_DATA_INIT
  381. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  382. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  383. hKeyMachine = HKEY_LOCAL_MACHINE;
  384. hKeyServices = NULL;
  385. dwSortOrder = SORT_ORDER_SERVICE;
  386. bReadWriteAccess = TRUE;
  387. dwRegAccessMask = KEY_READ | KEY_WRITE;
  388. pNameTable = NULL;
  389. dwLastElement = 0;
  390. dwListBoxHorizExtent = 0;
  391. dwTabStopCount = 1;
  392. dwTabStopArray[0] = 85;
  393. memset (&dwIdArray[0], 0, sizeof(dwIdArray));
  394. }
  395. CExctrlstDlg::~CExctrlstDlg()
  396. {
  397. if (hKeyServices != NULL && hKeyServices != INVALID_HANDLE_VALUE) {
  398. RegCloseKey(hKeyServices);
  399. }
  400. if (hKeyMachine != NULL && hKeyMachine != INVALID_HANDLE_VALUE
  401. && hKeyMachine != HKEY_LOCAL_MACHINE) {
  402. RegCloseKey(hKeyMachine);
  403. }
  404. if (pNameTable != NULL) {
  405. HeapFree (GetProcessHeap(), 0, pNameTable);
  406. pNameTable = NULL;
  407. dwLastElement = 0;
  408. }
  409. }
  410. void CExctrlstDlg::DoDataExchange(CDataExchange* pDX)
  411. {
  412. CDialog::DoDataExchange(pDX);
  413. //{{AFX_DATA_MAP(CExctrlstDlg)
  414. // NOTE: the ClassWizard will add DDX and DDV calls here
  415. //}}AFX_DATA_MAP
  416. }
  417. BEGIN_MESSAGE_MAP(CExctrlstDlg, CDialog)
  418. //{{AFX_MSG_MAP(CExctrlstDlg)
  419. ON_WM_PAINT()
  420. ON_WM_QUERYDRAGICON()
  421. ON_LBN_SELCHANGE(IDC_EXT_LIST, OnSelchangeExtList)
  422. ON_WM_DESTROY()
  423. ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  424. ON_BN_CLICKED(IDC_ABOUT, OnAbout)
  425. ON_EN_KILLFOCUS(IDC_MACHINE_NAME, OnKillfocusMachineName)
  426. ON_BN_CLICKED(IDC_SORT_LIBRARY, OnSortButton)
  427. ON_BN_CLICKED(IDC_SORT_SERVICE, OnSortButton)
  428. ON_BN_CLICKED(IDC_SORT_ID, OnSortButton)
  429. ON_BN_CLICKED(IDC_ENABLED_BTN, OnEnablePerf)
  430. ON_WM_SYSCOMMAND()
  431. //}}AFX_MSG_MAP
  432. END_MESSAGE_MAP()
  433. DWORD CExctrlstDlg::EnablePerfCounters (HKEY hKeyItem, DWORD dwNewValue)
  434. {
  435. DWORD dwStatus;
  436. DWORD dwType;
  437. DWORD dwValue;
  438. DWORD dwSize;
  439. DWORD dwReturn;
  440. switch (dwNewValue) {
  441. case ENABLE_PERF_CTR_QUERY:
  442. dwType = 0;
  443. dwSize = sizeof (dwValue);
  444. dwValue = 0;
  445. dwStatus = RegQueryValueExW (
  446. hKeyItem,
  447. cszDisablePerformanceCounters,
  448. NULL,
  449. &dwType,
  450. (LPBYTE)&dwValue,
  451. &dwSize);
  452. if ((dwStatus == ERROR_SUCCESS) && (dwType == REG_DWORD)) {
  453. switch (dwValue) {
  454. case 0: dwReturn = ENABLE_PERF_CTR_ENABLE; break;
  455. case 1: dwReturn = ENABLE_PERF_CTR_DISABLE; break;
  456. default: dwReturn = 0; break;
  457. }
  458. } else {
  459. // if the value is not present, or not = 1, then the perfctrs
  460. // are enabled
  461. dwReturn = ENABLE_PERF_CTR_ENABLE;
  462. }
  463. break;
  464. case ENABLE_PERF_CTR_ENABLE:
  465. dwType = REG_DWORD;
  466. dwSize = sizeof (dwValue);
  467. dwValue = 0;
  468. dwStatus = RegSetValueExW (
  469. hKeyItem,
  470. cszDisablePerformanceCounters,
  471. 0L,
  472. dwType,
  473. (LPBYTE)&dwValue,
  474. dwSize);
  475. if (dwStatus == ERROR_SUCCESS) {
  476. dwReturn = ENABLE_PERF_CTR_ENABLE;
  477. } else {
  478. dwReturn = 0;
  479. }
  480. break;
  481. case ENABLE_PERF_CTR_DISABLE:
  482. dwType = REG_DWORD;
  483. dwSize = sizeof (dwValue);
  484. dwValue = 1;
  485. dwStatus = RegSetValueExW (
  486. hKeyItem,
  487. cszDisablePerformanceCounters,
  488. 0L,
  489. dwType,
  490. (LPBYTE)&dwValue,
  491. dwSize);
  492. if (dwStatus == ERROR_SUCCESS) {
  493. dwReturn = ENABLE_PERF_CTR_DISABLE;
  494. } else {
  495. dwReturn = 0;
  496. }
  497. break;
  498. default:
  499. dwReturn = 0;
  500. }
  501. return dwReturn;
  502. }
  503. void CExctrlstDlg::ScanForExtensibleCounters ()
  504. {
  505. LONG lStatus = ERROR_SUCCESS;
  506. LONG lEnumStatus = ERROR_SUCCESS;
  507. DWORD dwServiceIndex;
  508. TCHAR szServiceSubKeyName[MAX_PATH];
  509. TCHAR szPerfSubKeyName[MAX_PATH+20];
  510. TCHAR szItemText[MAX_PATH];
  511. TCHAR szListText[MAX_PATH*2];
  512. DWORD dwNameSize;
  513. HKEY hKeyPerformance;
  514. UINT_PTR nListBoxEntry;
  515. DWORD dwItemSize, dwType, dwValue;
  516. HCURSOR hOldCursor;
  517. DWORD dwThisExtent;
  518. HDC hDcListBox;
  519. CWnd *pCWndListBox;
  520. hOldCursor = ::SetCursor (LoadCursor(NULL, IDC_WAIT));
  521. ResetListBox();
  522. if (hKeyServices == NULL) {
  523. // try read/write access
  524. lStatus = RegOpenKeyEx (hKeyMachine,
  525. cszServiceKeyName,
  526. 0L,
  527. dwRegAccessMask,
  528. &hKeyServices);
  529. if (lStatus != ERROR_SUCCESS) {
  530. // try read-only then
  531. dwRegAccessMask = KEY_READ;
  532. bReadWriteAccess = FALSE;
  533. lStatus = RegOpenKeyEx (hKeyMachine,
  534. cszServiceKeyName,
  535. 0L,
  536. dwRegAccessMask,
  537. &hKeyServices);
  538. if (lStatus != ERROR_SUCCESS) {
  539. // display Read Only message
  540. AfxMessageBox (IDS_READ_ONLY);
  541. } else {
  542. // fall through with error code
  543. // display no access message
  544. AfxMessageBox (IDS_NO_ACCESS);
  545. }
  546. }
  547. } else {
  548. lStatus = ERROR_SUCCESS;
  549. }
  550. if (lStatus == ERROR_SUCCESS) {
  551. pCWndListBox = GetDlgItem (IDC_EXT_LIST);
  552. hDcListBox = ::GetDC (pCWndListBox->m_hWnd);
  553. if (hDcListBox == NULL) {
  554. return;
  555. }
  556. dwServiceIndex = 0;
  557. dwNameSize = MAX_PATH;
  558. while ((lEnumStatus = RegEnumKeyEx (
  559. hKeyServices,
  560. dwServiceIndex,
  561. szServiceSubKeyName,
  562. &dwNameSize,
  563. NULL,
  564. NULL,
  565. NULL,
  566. NULL)) == ERROR_SUCCESS) {
  567. //try to open the perfkey under this key.
  568. lstrcpy (szPerfSubKeyName, szServiceSubKeyName);
  569. lstrcat (szPerfSubKeyName, cszPerformance);
  570. lStatus = RegOpenKeyEx (
  571. hKeyServices,
  572. szPerfSubKeyName,
  573. 0L,
  574. dwRegAccessMask,
  575. &hKeyPerformance);
  576. if (lStatus == ERROR_SUCCESS) {
  577. // look up the library name
  578. dwItemSize = MAX_PATH * sizeof(TCHAR);
  579. dwType = 0;
  580. lStatus = RegQueryValueEx (
  581. hKeyPerformance,
  582. cszLibrary,
  583. NULL,
  584. &dwType,
  585. (LPBYTE)&szItemText[0],
  586. &dwItemSize);
  587. if ((lStatus != ERROR_SUCCESS) ||
  588. ((dwType != REG_SZ) && dwType != REG_EXPAND_SZ)) {
  589. lstrcpy (szItemText, cszNotFound);
  590. }
  591. dwItemSize = sizeof(DWORD);
  592. dwType = 0;
  593. dwValue = 0;
  594. lStatus = RegQueryValueEx (
  595. hKeyPerformance,
  596. cszFirstCounter,
  597. NULL,
  598. &dwType,
  599. (LPBYTE)&dwValue,
  600. &dwItemSize);
  601. if ((lStatus != ERROR_SUCCESS) || (dwType != REG_DWORD)) {
  602. dwValue = 0;
  603. }
  604. // make the string for the list box here depending
  605. // on the selected sort order.
  606. if (dwSortOrder == SORT_ORDER_LIBRARY) {
  607. lstrcpy(szListText, szItemText);
  608. lstrcat(szListText, cszTab);
  609. lstrcat(szListText, szServiceSubKeyName);
  610. } else if (dwSortOrder == SORT_ORDER_ID) {
  611. _stprintf (szListText, cszSortIdFmt,
  612. dwValue, szServiceSubKeyName);
  613. } else { // default is sort by service
  614. lstrcpy(szListText, szServiceSubKeyName);
  615. lstrcat(szListText, cszTab);
  616. lstrcat(szListText, szItemText);
  617. }
  618. // add this name to the list box
  619. nListBoxEntry = SendDlgItemMessage(IDC_EXT_LIST,
  620. LB_ADDSTRING, 0, (LPARAM)&szListText[0]);
  621. if (nListBoxEntry != LB_ERR) {
  622. dwThisExtent = GetTabbedTextExtent (
  623. hDcListBox,
  624. szListText,
  625. lstrlen(szListText),
  626. (int)dwTabStopCount,
  627. (int *)&dwTabStopArray[0]);
  628. if (dwThisExtent > dwListBoxHorizExtent) {
  629. dwListBoxHorizExtent = dwThisExtent;
  630. SendDlgItemMessage(IDC_EXT_LIST,
  631. LB_SETHORIZONTALEXTENT,
  632. (WPARAM)LOWORD(dwListBoxHorizExtent), (LPARAM)0);
  633. }
  634. // save key to this entry in the registry
  635. SendDlgItemMessage(IDC_EXT_LIST,
  636. LB_SETITEMDATA, (WPARAM)nListBoxEntry,
  637. (LPARAM)hKeyPerformance);
  638. // Ignore PREFIX complains of handle leak for hKeyPerformance.
  639. //
  640. // local variable hKeyPerformance (registry key for "<service>\Performace") is
  641. // put in persistent data storage so that later EXCTRLST can retrieve its value in
  642. // CExctrlstDlg::UpdateDllInfo() and CExctrlstDlg::OnEnablePerf() and uses it as
  643. // a parameter in RegQueryValueEx() calls.
  644. // These registry keys will be released in CExctrlstDlg::ResetListBox().
  645. }
  646. else {
  647. // close the key since there's no point in
  648. // keeping it open
  649. RegCloseKey(hKeyPerformance);
  650. SendDlgItemMessage(IDC_EXT_LIST,
  651. LB_SETITEMDATA, (WPARAM) nListBoxEntry,
  652. (LPARAM) NULL);
  653. }
  654. }
  655. // reset for next loop
  656. dwServiceIndex++;
  657. dwNameSize = MAX_PATH;
  658. }
  659. ::ReleaseDC (pCWndListBox->m_hWnd, hDcListBox);
  660. }
  661. nListBoxEntry = SendDlgItemMessage (IDC_EXT_LIST, LB_GETCOUNT);
  662. if (nListBoxEntry > 0) {
  663. SendDlgItemMessage (IDC_EXT_LIST, LB_SETCURSEL, 0, 0);
  664. }
  665. ::SetCursor (hOldCursor);
  666. }
  667. void CExctrlstDlg::UpdateSystemInfo () {
  668. TCHAR szItemText[MAX_PATH];
  669. _stprintf (szItemText, cszIdFmt,
  670. dwIdArray[0], dwIdArray[0], cszSpace);
  671. SetDlgItemText (IDC_LAST_COUNTER_VALUE, szItemText);
  672. _stprintf (szItemText, cszIdFmt,
  673. dwIdArray[1], dwIdArray[1],
  674. dwIdArray[1] != dwIdArray[0] ? cszSplat : cszSpace);
  675. SetDlgItemText (IDC_LAST_TEXT_COUNTER_VALUE, szItemText);
  676. _stprintf (szItemText, cszIdFmt,
  677. dwIdArray[2], dwIdArray[2], cszSpace);
  678. SetDlgItemText (IDC_LAST_HELP_VALUE, szItemText);
  679. _stprintf (szItemText, cszIdFmt,
  680. dwIdArray[3], dwIdArray[3],
  681. dwIdArray[3] != dwIdArray[2] ? cszSplat : cszSpace);
  682. SetDlgItemText (IDC_LAST_TEXT_HELP_VALUE, szItemText);
  683. }
  684. void CExctrlstDlg::UpdateDllInfo () {
  685. HKEY hKeyItem;
  686. TCHAR szItemText[MAX_PATH];
  687. UINT_PTR nSelectedItem;
  688. LONG lStatus;
  689. DWORD dwType;
  690. DWORD dwValue;
  691. DWORD dwItemSize;
  692. BOOL bNoIndexValues = FALSE;
  693. DWORD dwEnabled;
  694. CString OpenProcName;
  695. CString LibraryName;
  696. HCURSOR hOldCursor;
  697. hOldCursor = ::SetCursor (LoadCursor(NULL, IDC_WAIT));
  698. OpenProcName.Empty();
  699. LibraryName.Empty();
  700. // update the performance counter information
  701. nSelectedItem = SendDlgItemMessage (IDC_EXT_LIST, LB_GETCURSEL);
  702. if (nSelectedItem != LB_ERR) {
  703. // get registry key for the selected item
  704. hKeyItem = (HKEY)SendDlgItemMessage(IDC_EXT_LIST, LB_GETITEMDATA,
  705. (WPARAM)nSelectedItem, 0);
  706. if (hKeyItem == NULL) {
  707. lStatus = ERROR_INVALID_HANDLE;
  708. }
  709. else {
  710. dwItemSize = MAX_PATH * sizeof(TCHAR);
  711. dwType = 0;
  712. lStatus = RegQueryValueEx(
  713. hKeyItem,
  714. cszLibrary,
  715. NULL,
  716. & dwType,
  717. (LPBYTE) & szItemText[0],
  718. & dwItemSize);
  719. }
  720. if ((lStatus != ERROR_SUCCESS) ||
  721. ((dwType != REG_SZ) && dwType != REG_EXPAND_SZ)) {
  722. lstrcpy (szItemText, cszNotFound);
  723. } else {
  724. LibraryName = szItemText;
  725. }
  726. SetDlgItemText (IDC_DLL_NAME, szItemText);
  727. dwItemSize = MAX_PATH * sizeof(TCHAR);
  728. dwType = 0;
  729. lStatus = RegQueryValueEx (
  730. hKeyItem,
  731. cszOpen,
  732. NULL,
  733. &dwType,
  734. (LPBYTE)&szItemText[0],
  735. &dwItemSize);
  736. if ((lStatus != ERROR_SUCCESS) ||
  737. ((dwType != REG_SZ) && dwType != REG_EXPAND_SZ)) {
  738. lstrcpy (szItemText, cszNotFound);
  739. } else {
  740. OpenProcName = szItemText;
  741. }
  742. SetDlgItemText (IDC_OPEN_PROC, szItemText);
  743. dwItemSize = MAX_PATH * sizeof(TCHAR);
  744. dwType = 0;
  745. lStatus = RegQueryValueEx (
  746. hKeyItem,
  747. cszCollect,
  748. NULL,
  749. &dwType,
  750. (LPBYTE)&szItemText[0],
  751. &dwItemSize);
  752. if ((lStatus != ERROR_SUCCESS) ||
  753. ((dwType != REG_SZ) && dwType != REG_EXPAND_SZ)) {
  754. lstrcpy (szItemText, cszNotFound);
  755. }
  756. SetDlgItemText (IDC_COLLECT_PROC, szItemText);
  757. dwItemSize = MAX_PATH * sizeof(TCHAR);
  758. dwType = 0;
  759. lStatus = RegQueryValueEx (
  760. hKeyItem,
  761. cszClose,
  762. NULL,
  763. &dwType,
  764. (LPBYTE)&szItemText[0],
  765. &dwItemSize);
  766. if ((lStatus != ERROR_SUCCESS) ||
  767. ((dwType != REG_SZ) && dwType != REG_EXPAND_SZ)) {
  768. lstrcpy (szItemText, cszNotFound);
  769. }
  770. SetDlgItemText (IDC_CLOSE_PROC, szItemText);
  771. dwItemSize = sizeof(DWORD);
  772. dwType = 0;
  773. dwValue = 0;
  774. lStatus = RegQueryValueEx (
  775. hKeyItem,
  776. cszFirstCounter,
  777. NULL,
  778. &dwType,
  779. (LPBYTE)&dwValue,
  780. &dwItemSize);
  781. if ((lStatus != ERROR_SUCCESS) || (dwType != REG_DWORD)) {
  782. lstrcpy (szItemText, cszNotFound);
  783. bNoIndexValues = TRUE;
  784. } else {
  785. _stprintf (szItemText, cszServIdFmt, dwValue, IndexHasString (dwValue) ? cszSpace : cszSplat);
  786. }
  787. SetDlgItemText (IDC_FIRST_CTR_ID, szItemText);
  788. dwItemSize = sizeof(DWORD);
  789. dwType = 0;
  790. dwValue = 0;
  791. lStatus = RegQueryValueEx (
  792. hKeyItem,
  793. cszLastCounter,
  794. NULL,
  795. &dwType,
  796. (LPBYTE)&dwValue,
  797. &dwItemSize);
  798. if ((lStatus != ERROR_SUCCESS) || (dwType != REG_DWORD)) {
  799. lstrcpy (szItemText, cszNotFound);
  800. } else {
  801. _stprintf (szItemText, cszServIdFmt, dwValue, IndexHasString (dwValue) ? cszSpace : cszSplat);
  802. }
  803. SetDlgItemText (IDC_LAST_CTR_ID, szItemText);
  804. dwItemSize = sizeof(DWORD);
  805. dwType = 0;
  806. dwValue = 0;
  807. lStatus = RegQueryValueEx (
  808. hKeyItem,
  809. cszFirstHelp,
  810. NULL,
  811. &dwType,
  812. (LPBYTE)&dwValue,
  813. &dwItemSize);
  814. if ((lStatus != ERROR_SUCCESS) || (dwType != REG_DWORD)) {
  815. lstrcpy (szItemText, cszNotFound);
  816. bNoIndexValues = TRUE;
  817. } else {
  818. _stprintf (szItemText, cszServIdFmt, dwValue, IndexHasString (dwValue) ? cszSpace : cszSplat);
  819. }
  820. SetDlgItemText (IDC_FIRST_HELP_ID, szItemText);
  821. dwItemSize = sizeof(DWORD);
  822. dwType = 0;
  823. dwValue = 0;
  824. lStatus = RegQueryValueEx (
  825. hKeyItem,
  826. cszLastHelp,
  827. NULL,
  828. &dwType,
  829. (LPBYTE)&dwValue,
  830. &dwItemSize);
  831. if ((lStatus != ERROR_SUCCESS) || (dwType != REG_DWORD)) {
  832. lstrcpy (szItemText, cszNotFound);
  833. } else {
  834. _stprintf (szItemText, cszServIdFmt, dwValue, IndexHasString (dwValue) ? cszSpace : cszSplat);
  835. }
  836. SetDlgItemText (IDC_LAST_HELP_ID, szItemText);
  837. if (bNoIndexValues) {
  838. // test to see if this is a "standard" i.e. Microsoft provided
  839. // extensible counter or simply one that hasn't been completely
  840. // installed
  841. if (IsMsObject(&LibraryName)) {
  842. SetDlgItemText (IDC_FIRST_HELP_ID, cszNA);
  843. SetDlgItemText (IDC_LAST_HELP_ID, cszNA);
  844. SetDlgItemText (IDC_FIRST_CTR_ID, cszNA);
  845. SetDlgItemText (IDC_LAST_CTR_ID, cszNA);
  846. }
  847. }
  848. GetDlgItem(IDC_ENABLED_BTN)->ShowWindow (bReadWriteAccess ? SW_SHOW : SW_HIDE);
  849. GetDlgItem(IDC_ENABLED_BTN)->EnableWindow (bReadWriteAccess);
  850. dwEnabled = EnablePerfCounters (hKeyItem, ENABLE_PERF_CTR_QUERY);
  851. if (bReadWriteAccess) {
  852. // then set the check box
  853. CheckDlgButton (IDC_ENABLED_BTN, dwEnabled == ENABLE_PERF_CTR_ENABLE ? 1 : 0);
  854. GetDlgItem(IDC_DISABLED_TEXT)->ShowWindow (SW_HIDE);
  855. } else {
  856. // update the text message
  857. GetDlgItem(IDC_DISABLED_TEXT)->ShowWindow (
  858. (!(dwEnabled == ENABLE_PERF_CTR_ENABLE)) ?
  859. SW_SHOW : SW_HIDE);
  860. GetDlgItem(IDC_DISABLED_TEXT)->EnableWindow (TRUE);
  861. }
  862. }
  863. ::SetCursor (hOldCursor);
  864. }
  865. void CExctrlstDlg::ResetListBox ()
  866. {
  867. INT_PTR nItemCount;
  868. INT nThisItem;
  869. HKEY hKeyItem;
  870. nItemCount = SendDlgItemMessage (IDC_EXT_LIST, LB_GETCOUNT);
  871. nThisItem = 0;
  872. while (nThisItem > nItemCount) {
  873. hKeyItem = (HKEY) SendDlgItemMessage(IDC_EXT_LIST,
  874. LB_GETITEMDATA, (WPARAM)nThisItem);
  875. if (hKeyItem != NULL) RegCloseKey(hKeyItem);
  876. nThisItem++;
  877. }
  878. SendDlgItemMessage (IDC_EXT_LIST, LB_RESETCONTENT);
  879. dwListBoxHorizExtent = 0;
  880. SendDlgItemMessage(IDC_EXT_LIST,
  881. LB_SETHORIZONTALEXTENT,
  882. (WPARAM)LOWORD(dwListBoxHorizExtent), (LPARAM)0);
  883. }
  884. void CExctrlstDlg::SetSortButtons()
  885. {
  886. DWORD dwBtn;
  887. switch (dwSortOrder) {
  888. case SORT_ORDER_LIBRARY: dwBtn = IDC_SORT_LIBRARY; break;
  889. case SORT_ORDER_SERVICE: dwBtn = IDC_SORT_SERVICE; break;
  890. case SORT_ORDER_ID: dwBtn = IDC_SORT_ID; break;
  891. default: dwBtn = IDC_SORT_SERVICE; break;
  892. }
  893. CheckRadioButton (
  894. IDC_SORT_LIBRARY,
  895. IDC_SORT_ID,
  896. dwBtn);
  897. }
  898. /////////////////////////////////////////////////////////////////////////////
  899. // CExctrlstDlg message handlers
  900. BOOL CExctrlstDlg::OnInitDialog()
  901. {
  902. HCURSOR hOldCursor;
  903. DWORD dwLength;
  904. hOldCursor = ::SetCursor (::LoadCursor (NULL, IDC_WAIT));
  905. CDialog::OnInitDialog();
  906. CenterWindow();
  907. lstrcpy (szThisComputerName, cszDoubleBackslash);
  908. dwLength = MAX_COMPUTERNAME_LENGTH+1;
  909. GetComputerName (&szThisComputerName[2], &dwLength);
  910. lstrcpy (szComputerName, szThisComputerName);
  911. SetDlgItemText (IDC_MACHINE_NAME, szComputerName);
  912. hKeyMachine = HKEY_LOCAL_MACHINE;
  913. pNameTable = BuildNameTable (
  914. szComputerName,
  915. cszDefaultLangId,
  916. &dwLastElement, // size of array in elements
  917. &dwIdArray[0]);
  918. SendDlgItemMessage (IDC_MACHINE_NAME, EM_LIMITTEXT,
  919. (WPARAM)MAX_COMPUTERNAME_LENGTH+2, 0); // include 2 leading backslash
  920. SendDlgItemMessage (IDC_EXT_LIST, LB_SETTABSTOPS,
  921. (WPARAM)dwTabStopCount, (LPARAM)&dwTabStopArray[0]);
  922. SetSortButtons();
  923. ScanForExtensibleCounters(); //.checks for access to the registry
  924. UpdateSystemInfo();
  925. // set the check box to the appropriate state
  926. UpdateDllInfo ();
  927. ::SetCursor(hOldCursor);
  928. return TRUE; // return TRUE unless you set the focus to a control
  929. }
  930. // If you add a minimize button to your dialog, you will need the code below
  931. // to draw the icon. For MFC applications using the document/view model,
  932. // this is automatically done for you by the framework.
  933. void CExctrlstDlg::OnPaint()
  934. {
  935. if (IsIconic())
  936. {
  937. CPaintDC dc(this); // device context for painting
  938. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  939. // Center icon in client rectangle
  940. int cxIcon = GetSystemMetrics(SM_CXICON);
  941. int cyIcon = GetSystemMetrics(SM_CYICON);
  942. CRect rect;
  943. GetClientRect(&rect);
  944. int x = (rect.Width() - cxIcon + 1) / 2;
  945. int y = (rect.Height() - cyIcon + 1) / 2;
  946. // Draw the icon
  947. dc.DrawIcon(x, y, m_hIcon);
  948. }
  949. else
  950. {
  951. CDialog::OnPaint();
  952. }
  953. }
  954. // The system calls this to obtain the cursor to display while the user drags
  955. // the minimized window.
  956. HCURSOR CExctrlstDlg::OnQueryDragIcon()
  957. {
  958. return (HCURSOR) m_hIcon;
  959. }
  960. void CExctrlstDlg::OnSelchangeExtList()
  961. {
  962. UpdateDllInfo ();
  963. }
  964. void CExctrlstDlg::OnDestroy()
  965. {
  966. ResetListBox();
  967. CDialog::OnDestroy();
  968. }
  969. void CExctrlstDlg::OnAbout()
  970. {
  971. CAbout dlg;
  972. dlg.DoModal();
  973. }
  974. void CExctrlstDlg::OnRefresh()
  975. {
  976. HCURSOR hOldCursor;
  977. hOldCursor = ::SetCursor (::LoadCursor (NULL, IDC_WAIT));
  978. ScanForExtensibleCounters();
  979. if (pNameTable != NULL) {
  980. HeapFree (GetProcessHeap(), 0, pNameTable);
  981. pNameTable = NULL;
  982. dwLastElement = 0;
  983. }
  984. pNameTable = BuildNameTable (
  985. szComputerName,
  986. cszDefaultLangId,
  987. &dwLastElement, // size of array in elements
  988. &dwIdArray[0]);
  989. UpdateSystemInfo();
  990. UpdateDllInfo ();
  991. ::SetCursor(hOldCursor);
  992. }
  993. void CExctrlstDlg::OnKillfocusMachineName()
  994. {
  995. TCHAR szNewMachineName[MAX_PATH];
  996. HKEY hKeyNewMachine;
  997. LONG lStatus;
  998. HCURSOR hOldCursor;
  999. hOldCursor = ::SetCursor (::LoadCursor (NULL, IDC_WAIT));
  1000. GetDlgItemText (IDC_MACHINE_NAME, szNewMachineName, MAX_PATH);
  1001. if (lstrcmpi(szComputerName, szNewMachineName) != 0) {
  1002. // a new computer has been entered so try to connect to it
  1003. lStatus = RegConnectRegistry (szNewMachineName,
  1004. HKEY_LOCAL_MACHINE, &hKeyNewMachine);
  1005. if (lStatus == ERROR_SUCCESS) {
  1006. RegCloseKey (hKeyServices); // close the old key
  1007. hKeyServices = NULL; // clear it
  1008. bReadWriteAccess = TRUE; // reset the access variables
  1009. dwRegAccessMask = KEY_READ | KEY_WRITE;
  1010. if (hKeyMachine != NULL && hKeyMachine != INVALID_HANDLE_VALUE
  1011. && hKeyMachine != HKEY_LOCAL_MACHINE) {
  1012. RegCloseKey(hKeyMachine); // close the old machine
  1013. }
  1014. hKeyMachine = hKeyNewMachine; // update to the new machine
  1015. lstrcpy (szComputerName, szNewMachineName); // update the name
  1016. OnRefresh(); // get new counters
  1017. } else {
  1018. SetDlgItemText (IDC_MACHINE_NAME, szComputerName);
  1019. }
  1020. } else {
  1021. // the machine name has not changed
  1022. }
  1023. ::SetCursor (hOldCursor);
  1024. }
  1025. void CExctrlstDlg::OnSortButton()
  1026. {
  1027. if (IsDlgButtonChecked(IDC_SORT_LIBRARY)) {
  1028. dwSortOrder = SORT_ORDER_LIBRARY;
  1029. } else if (IsDlgButtonChecked(IDC_SORT_SERVICE)) {
  1030. dwSortOrder = SORT_ORDER_SERVICE;
  1031. } else if (IsDlgButtonChecked(IDC_SORT_ID)) {
  1032. dwSortOrder = SORT_ORDER_ID;
  1033. }
  1034. ScanForExtensibleCounters();
  1035. UpdateDllInfo ();
  1036. }
  1037. void CExctrlstDlg::OnEnablePerf()
  1038. {
  1039. HKEY hKeyItem;
  1040. UINT_PTR nSelectedItem;
  1041. DWORD dwNewValue;
  1042. nSelectedItem = SendDlgItemMessage (IDC_EXT_LIST, LB_GETCURSEL);
  1043. if (nSelectedItem != LB_ERR) {
  1044. // get registry key for the selected item
  1045. hKeyItem = (HKEY)SendDlgItemMessage (IDC_EXT_LIST, LB_GETITEMDATA,
  1046. (WPARAM)nSelectedItem, 0);
  1047. if (hKeyItem != NULL) {
  1048. // get selected perf item and the corre
  1049. dwNewValue = IsDlgButtonChecked(IDC_ENABLED_BTN) ?
  1050. ENABLE_PERF_CTR_ENABLE :
  1051. ENABLE_PERF_CTR_DISABLE;
  1052. if (EnablePerfCounters (hKeyItem, dwNewValue) == 0) {
  1053. MessageBeep(0xFFFFFFFF);
  1054. // then it failed so reset to the curent value
  1055. dwNewValue = EnablePerfCounters (hKeyItem, ENABLE_PERF_CTR_QUERY);
  1056. CheckDlgButton (IDC_ENABLED_BTN, dwNewValue == ENABLE_PERF_CTR_ENABLE ? 1 : 0);
  1057. }
  1058. }
  1059. }
  1060. }
  1061. void CExctrlstDlg::OnSysCommand(UINT nID, LPARAM lParam)
  1062. {
  1063. switch (nID) {
  1064. case SC_CLOSE:
  1065. EndDialog(IDOK);
  1066. break;
  1067. default:
  1068. CDialog::OnSysCommand (nID, lParam);
  1069. break;
  1070. }
  1071. }
  1072. /////////////////////////////////////////////////////////////////////////////
  1073. // CAbout dialog
  1074. CAbout::CAbout(CWnd* pParent /*=NULL*/)
  1075. : CDialog(CAbout::IDD, pParent)
  1076. {
  1077. //{{AFX_DATA_INIT(CAbout)
  1078. // NOTE: the ClassWizard will add member initialization here
  1079. //}}AFX_DATA_INIT
  1080. }
  1081. void CAbout::DoDataExchange(CDataExchange* pDX)
  1082. {
  1083. CDialog::DoDataExchange(pDX);
  1084. //{{AFX_DATA_MAP(CAbout)
  1085. // NOTE: the ClassWizard will add DDX and DDV calls here
  1086. //}}AFX_DATA_MAP
  1087. }
  1088. BOOL CAbout::OnInitDialog()
  1089. {
  1090. CDialog::OnInitDialog();
  1091. TCHAR buffer[512];
  1092. TCHAR strProgram[1024];
  1093. DWORD dw;
  1094. BYTE* pVersionInfo;
  1095. LPTSTR pVersion = NULL;
  1096. LPTSTR pProduct = NULL;
  1097. LPTSTR pCopyRight = NULL;
  1098. dw = GetModuleFileName(NULL, strProgram, 1024);
  1099. if( dw>0 ){
  1100. dw = GetFileVersionInfoSize( strProgram, &dw );
  1101. if( dw > 0 ){
  1102. pVersionInfo = (BYTE*)malloc(dw);
  1103. if( NULL != pVersionInfo ){
  1104. if(GetFileVersionInfo( strProgram, 0, dw, pVersionInfo )){
  1105. LPDWORD lptr = NULL;
  1106. VerQueryValue( pVersionInfo, _T("\\VarFileInfo\\Translation"), (void**)&lptr, (UINT*)&dw );
  1107. if( lptr != NULL ){
  1108. _stprintf( buffer, _T("\\StringFileInfo\\%04x%04x\\%s"), LOWORD(*lptr), HIWORD(*lptr), _T("ProductVersion") );
  1109. VerQueryValue( pVersionInfo, buffer, (void**)&pVersion, (UINT*)&dw );
  1110. _stprintf( buffer, _T("\\StringFileInfo\\%04x%04x\\%s"), LOWORD(*lptr), HIWORD(*lptr), _T("OriginalFilename") );
  1111. VerQueryValue( pVersionInfo, buffer, (void**)&pProduct, (UINT*)&dw );
  1112. _stprintf( buffer, _T("\\StringFileInfo\\%04x%04x\\%s"), LOWORD(*lptr), HIWORD(*lptr), _T("LegalCopyright") );
  1113. VerQueryValue( pVersionInfo, buffer, (void**)&pCopyRight, (UINT*)&dw );
  1114. }
  1115. if( pProduct != NULL && pVersion != NULL && pCopyRight != NULL ){
  1116. GetDlgItem(IDC_COPYRIGHT)->SetWindowText( pCopyRight );
  1117. GetDlgItem(IDC_VERSION)->SetWindowText( pVersion );
  1118. }
  1119. }
  1120. free( pVersionInfo );
  1121. }
  1122. }
  1123. }
  1124. return TRUE;
  1125. }
  1126. BEGIN_MESSAGE_MAP(CAbout, CDialog)
  1127. //{{AFX_MSG_MAP(CAbout)
  1128. // NOTE: the ClassWizard will add message map macros here
  1129. //}}AFX_MSG_MAP
  1130. END_MESSAGE_MAP()
  1131. /////////////////////////////////////////////////////////////////////////////
  1132. // CAbout message handlers