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.

914 lines
28 KiB

  1. #include <windows.h>
  2. #include <winperf.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <tchar.h>
  7. #include "showperf.h"
  8. #include "perfdata.h"
  9. #include "resource.h"
  10. #include "maindlg.h"
  11. static PPERF_DATA_BLOCK pMainPerfData = NULL; // pointer to perfdata block
  12. static LPWSTR *szNameTable = NULL; // pointer to perf name table
  13. static DWORD dwLastName = 0;
  14. static TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH+3];
  15. static TCHAR szThisComputerName[MAX_COMPUTERNAME_LENGTH+3];
  16. static HKEY hKeyMachine = NULL;
  17. static HKEY hKeyPerformance = NULL;
  18. #define NUM_TAB_STOPS 3
  19. static INT nDataListTabs[NUM_TAB_STOPS] = {
  20. 26
  21. , 160
  22. , 235
  23. };
  24. static
  25. BOOL
  26. LoadObjectList (
  27. IN HWND hDlg,
  28. IN LPCTSTR szMatchItem
  29. )
  30. {
  31. PPERF_OBJECT_TYPE pObject;
  32. HWND hWndObjectCB;
  33. UINT nInitial = 0;
  34. UINT nIndex;
  35. TCHAR szNameBuffer[MAX_PATH];
  36. DWORD dwThisObject = 0;
  37. DWORD dwCounterType;
  38. BOOL bReturn = TRUE;
  39. hWndObjectCB = GetDlgItem (hDlg, IDC_OBJECT);
  40. if (IsDlgButtonChecked (hDlg, IDC_INCLUDE_COSTLY) == CHECKED) {
  41. dwCounterType = 1;
  42. } else {
  43. dwCounterType = 0;
  44. }
  45. // get current data block
  46. if (GetSystemPerfData (hKeyPerformance, &pMainPerfData,
  47. dwCounterType) == ERROR_SUCCESS) {
  48. // data acquired so clear combo and display
  49. SendMessage (hWndObjectCB, CB_RESETCONTENT, 0, 0);
  50. pObject = FirstObject (pMainPerfData);
  51. __try {
  52. for (dwThisObject = 0; dwThisObject < pMainPerfData->NumObjectTypes; dwThisObject++) {
  53. // get counter object name here...
  54. _stprintf (szNameBuffer, (LPCTSTR)TEXT("(%d) %s"),
  55. pObject->ObjectNameTitleIndex,
  56. pObject->ObjectNameTitleIndex <= dwLastName ?
  57. szNameTable[pObject->ObjectNameTitleIndex] : (LPCTSTR)TEXT("Name not loaded"));
  58. nIndex = (UINT)SendMessage (hWndObjectCB, CB_INSERTSTRING, (WPARAM)-1,
  59. (LPARAM)szNameBuffer);
  60. if (nIndex != CB_ERR) {
  61. // save object pointer
  62. SendMessage (hWndObjectCB, CB_SETITEMDATA,
  63. (WPARAM)nIndex, (LPARAM)pObject);
  64. if (pObject->ObjectNameTitleIndex == (DWORD)pMainPerfData->DefaultObject) {
  65. // remember this index to set the default object
  66. nInitial = nIndex;
  67. }
  68. }
  69. pObject = NextObject(pObject);
  70. }
  71. } __except (EXCEPTION_EXECUTE_HANDLER) {
  72. _stprintf (szNameBuffer,
  73. (LPCTSTR)TEXT("An exception (0x%8.8x) occured in object block # %d returned by the system."),
  74. GetExceptionCode (), dwThisObject+1);
  75. MessageBox (hDlg, szNameBuffer, (LPCTSTR)TEXT("Data Error"), MB_OK);
  76. // update the data buffer so that only the valid objects
  77. // are accessed in the future.
  78. pMainPerfData->NumObjectTypes = dwThisObject-1;
  79. }
  80. if (szMatchItem == NULL) {
  81. SendMessage (hWndObjectCB, CB_SETCURSEL, (WPARAM)nInitial, 0);
  82. } else {
  83. // match to arg string as best as possible
  84. if (SendMessage (hWndObjectCB, CB_SELECTSTRING, (WPARAM)-1,
  85. (LPARAM)szMatchItem) == CB_ERR) {
  86. // no match found so use default
  87. SendMessage (hWndObjectCB, CB_SETCURSEL, (WPARAM)nInitial, 0);
  88. }
  89. }
  90. } else {
  91. DisplayMessageBox (hDlg,
  92. IDS_UNABLE_GET_DATA,
  93. IDS_APP_ERROR, MB_OK);
  94. bReturn = FALSE;
  95. }
  96. return bReturn;
  97. }
  98. static
  99. LoadInstanceList (
  100. IN HWND hDlg,
  101. IN LPCTSTR szMatchItem
  102. )
  103. {
  104. PPERF_OBJECT_TYPE pObject;
  105. PPERF_OBJECT_TYPE pParentObject;
  106. PPERF_COUNTER_BLOCK pCounterBlock;
  107. PPERF_INSTANCE_DEFINITION pInstance;
  108. PPERF_INSTANCE_DEFINITION pParentInstance;
  109. UINT nCbSel;
  110. LONG lThisInstance;
  111. TCHAR szNameBuffer[MAX_PATH];
  112. TCHAR szParentName[MAX_PATH];
  113. UINT nIndex;
  114. nCbSel = (UINT)SendDlgItemMessage (hDlg, IDC_OBJECT, CB_GETCURSEL, 0, 0);
  115. if (nCbSel != CB_ERR) {
  116. pObject = (PPERF_OBJECT_TYPE)SendDlgItemMessage (hDlg, IDC_OBJECT, CB_GETITEMDATA,
  117. (WPARAM)nCbSel, 0);
  118. if (pObject->NumInstances == PERF_NO_INSTANCES) {
  119. // no instances so...
  120. // clear old contents
  121. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_RESETCONTENT, 0, 0);
  122. // add display text
  123. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_INSERTSTRING, (WPARAM)-1,
  124. (LPARAM)TEXT("<No Instances>"));
  125. // select this (and only) string
  126. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_SETCURSEL, 0, 0);
  127. // get pointer to counter data
  128. pCounterBlock = (PPERF_COUNTER_BLOCK)((LPBYTE)pObject + pObject->DefinitionLength);
  129. // and save it as item data
  130. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_SETITEMDATA, 0,
  131. (LPARAM)pCounterBlock);
  132. // finally grey the window to prevent selections
  133. EnableWindow (GetDlgItem (hDlg, IDC_INSTANCE), FALSE);
  134. } else {
  135. //enable window
  136. EnableWindow (GetDlgItem (hDlg, IDC_INSTANCE), TRUE);
  137. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_RESETCONTENT, 0, 0);
  138. pInstance = FirstInstance (pObject);
  139. for (lThisInstance = 0; lThisInstance < pObject->NumInstances; lThisInstance++) {
  140. pParentObject = GetObjectDefByTitleIndex (
  141. pMainPerfData,
  142. pInstance->ParentObjectTitleIndex);
  143. if (pParentObject != NULL) {
  144. pParentInstance = GetInstance (pParentObject,
  145. pInstance->ParentObjectInstance);
  146. } else {
  147. pParentInstance = NULL;
  148. }
  149. if (pParentInstance != NULL) {
  150. if (pParentInstance->UniqueID < 0) {
  151. // use the instance name
  152. wcsncpy (szParentName,
  153. (LPWSTR)((LPBYTE)pParentInstance+pParentInstance->NameOffset),
  154. pParentInstance->NameLength);
  155. lstrcat (szParentName, (LPCTSTR)TEXT("==>"));
  156. } else {
  157. // use the instance number
  158. _stprintf (szParentName, (LPCTSTR)TEXT("[%d]==>"),
  159. pParentInstance->UniqueID);
  160. }
  161. } else {
  162. // unknown parent
  163. *szParentName = 0;
  164. }
  165. if (pInstance->UniqueID < 0) {
  166. // use the instance name
  167. wcsncpy (szNameBuffer,
  168. (LPWSTR)((LPBYTE)pInstance+pInstance->NameOffset),
  169. pInstance->NameLength);
  170. } else {
  171. // use the instance number
  172. _stprintf (szNameBuffer, (LPCTSTR)TEXT("(%d)"),
  173. pInstance->UniqueID);
  174. }
  175. lstrcat (szParentName, szNameBuffer);
  176. nIndex = (UINT)SendDlgItemMessage (hDlg, IDC_INSTANCE,
  177. CB_INSERTSTRING, (WPARAM)-1,
  178. (LPARAM)szParentName);
  179. if (nIndex != CB_ERR) {
  180. // save pointer to counter block
  181. pCounterBlock = (PERF_COUNTER_BLOCK *)
  182. ((PCHAR) pInstance + pInstance->ByteLength);
  183. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_SETITEMDATA,
  184. (WPARAM)nIndex, (LPARAM)pCounterBlock);
  185. }
  186. pInstance = NextInstance (pInstance);
  187. }
  188. if (szMatchItem == NULL) {
  189. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_SETCURSEL, 0, 0);
  190. } else {
  191. if (SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_SELECTSTRING,
  192. (WPARAM)-1, (LPARAM)szMatchItem) == CB_ERR) {
  193. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_SETCURSEL, 0, 0);
  194. }
  195. }
  196. }
  197. } else {
  198. // no object selected
  199. // clear old contents
  200. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_RESETCONTENT, 0, 0);
  201. // add display text
  202. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_INSERTSTRING, (WPARAM)-1,
  203. (LPARAM)TEXT("<No object selected>"));
  204. // select this (and only) string
  205. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_SETCURSEL, 0, 0);
  206. // and save null pointer as item data
  207. SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_SETITEMDATA, 0,
  208. (LPARAM)0);
  209. // finally grey the window to prevent selections
  210. EnableWindow (GetDlgItem (hDlg, IDC_INSTANCE), FALSE);
  211. }
  212. return TRUE;
  213. }
  214. static
  215. LPCTSTR
  216. GetCounterTypeName (
  217. IN DWORD dwCounterType
  218. )
  219. {
  220. UINT nTypeString = 0;
  221. switch (dwCounterType) {
  222. case PERF_COUNTER_COUNTER:
  223. nTypeString = IDS_TYPE_COUNTER_COUNTER ;
  224. break;
  225. case PERF_COUNTER_TIMER:
  226. nTypeString = IDS_TYPE_COUNTER_TIMER ;
  227. break;
  228. case PERF_COUNTER_QUEUELEN_TYPE:
  229. nTypeString = IDS_TYPE_COUNTER_QUEUELEN ;
  230. break;
  231. case PERF_COUNTER_LARGE_QUEUELEN_TYPE:
  232. nTypeString = IDS_TYPE_COUNTER_LARGE_QUEUELEN ;
  233. break;
  234. case PERF_COUNTER_100NS_QUEUELEN_TYPE:
  235. nTypeString = IDS_TYPE_COUNTER_100NS_QUEUELEN ;
  236. break;
  237. case PERF_COUNTER_OBJ_TIME_QUEUELEN_TYPE:
  238. nTypeString = IDS_TYPE_COUNTER_OBJ_TIME_QUEUELEN ;
  239. break;
  240. case PERF_COUNTER_BULK_COUNT:
  241. nTypeString = IDS_TYPE_COUNTER_BULK_COUNT ;
  242. break;
  243. case PERF_COUNTER_TEXT:
  244. nTypeString = IDS_TYPE_COUNTER_TEXT ;
  245. break;
  246. case PERF_COUNTER_RAWCOUNT:
  247. nTypeString = IDS_TYPE_COUNTER_RAWCOUNT ;
  248. break;
  249. case PERF_COUNTER_LARGE_RAWCOUNT:
  250. nTypeString = IDS_TYPE_COUNTER_LARGE_RAW ;
  251. break;
  252. case PERF_COUNTER_RAWCOUNT_HEX:
  253. nTypeString = IDS_TYPE_COUNTER_RAW_HEX ;
  254. break;
  255. case PERF_COUNTER_LARGE_RAWCOUNT_HEX:
  256. nTypeString = IDS_TYPE_COUNTER_LARGE_RAW_HEX ;
  257. break;
  258. case PERF_SAMPLE_FRACTION:
  259. nTypeString = IDS_TYPE_SAMPLE_FRACTION ;
  260. break;
  261. case PERF_SAMPLE_COUNTER:
  262. nTypeString = IDS_TYPE_SAMPLE_COUNTER ;
  263. break;
  264. case PERF_COUNTER_NODATA:
  265. nTypeString = IDS_TYPE_COUNTER_NODATA ;
  266. break;
  267. case PERF_COUNTER_TIMER_INV:
  268. nTypeString = IDS_TYPE_COUNTER_TIMER_INV ;
  269. break;
  270. case PERF_SAMPLE_BASE:
  271. nTypeString = IDS_TYPE_SAMPLE_BASE ;
  272. break;
  273. case PERF_AVERAGE_TIMER:
  274. nTypeString = IDS_TYPE_AVERAGE_TIMER ;
  275. break;
  276. case PERF_AVERAGE_BASE:
  277. nTypeString = IDS_TYPE_AVERAGE_BASE ;
  278. break;
  279. case PERF_AVERAGE_BULK:
  280. nTypeString = IDS_TYPE_AVERAGE_BULK ;
  281. break;
  282. case PERF_OBJ_TIME_TIMER:
  283. nTypeString = IDS_TYPE_OBJ_TIME_TIMER ;
  284. break;
  285. case PERF_100NSEC_TIMER:
  286. nTypeString = IDS_TYPE_100NS_TIMER ;
  287. break;
  288. case PERF_100NSEC_TIMER_INV:
  289. nTypeString = IDS_TYPE_100NS_TIMER_INV ;
  290. break;
  291. case PERF_COUNTER_MULTI_TIMER:
  292. nTypeString = IDS_TYPE_MULTI_TIMER ;
  293. break;
  294. case PERF_COUNTER_MULTI_TIMER_INV:
  295. nTypeString = IDS_TYPE_MULTI_TIMER_INV ;
  296. break;
  297. case PERF_COUNTER_MULTI_BASE:
  298. nTypeString = IDS_TYPE_MULTI_BASE ;
  299. break;
  300. case PERF_100NSEC_MULTI_TIMER:
  301. nTypeString = IDS_TYPE_100NS_MULTI_TIMER ;
  302. break;
  303. case PERF_100NSEC_MULTI_TIMER_INV:
  304. nTypeString = IDS_TYPE_100NS_MULTI_TIMER_INV ;
  305. break;
  306. case PERF_RAW_FRACTION:
  307. nTypeString = IDS_TYPE_RAW_FRACTION ;
  308. break;
  309. case PERF_LARGE_RAW_FRACTION:
  310. nTypeString = IDS_TYPE_LARGE_RAW_FRACTION ;
  311. break;
  312. case PERF_RAW_BASE:
  313. nTypeString = IDS_TYPE_RAW_BASE ;
  314. break;
  315. case PERF_LARGE_RAW_BASE:
  316. nTypeString = IDS_TYPE_LARGE_RAW_BASE ;
  317. break;
  318. case PERF_ELAPSED_TIME:
  319. nTypeString = IDS_TYPE_ELAPSED_TIME ;
  320. break;
  321. case PERF_COUNTER_HISTOGRAM_TYPE:
  322. nTypeString = IDS_TYPE_HISTOGRAM ;
  323. break;
  324. case PERF_COUNTER_DELTA:
  325. nTypeString = IDS_TYPE_COUNTER_DELTA ;
  326. break;
  327. case PERF_COUNTER_LARGE_DELTA:
  328. nTypeString = IDS_TYPE_COUNTER_LARGE_DELTA;
  329. break;
  330. case PERF_PRECISION_SYSTEM_TIMER:
  331. nTypeString = IDS_TYPE_PRECISION_SYSTEM_TIMER;
  332. break;
  333. case PERF_PRECISION_100NS_TIMER:
  334. nTypeString = IDS_TYPE_PRECISION_100NS_TIMER ;
  335. break;
  336. case PERF_PRECISION_OBJECT_TIMER:
  337. nTypeString = IDS_TYPE_PRECISION_OBJECT_TIMER;
  338. break;
  339. default:
  340. nTypeString = 0;
  341. break;
  342. }
  343. if (nTypeString != 0) {
  344. return GetStringResource (NULL, nTypeString);
  345. } else {
  346. return (LPCTSTR)TEXT("");
  347. }
  348. }
  349. static
  350. BOOL
  351. ShowCounterData (
  352. IN HWND hDlg,
  353. IN LONG lDisplayIndex
  354. )
  355. {
  356. PPERF_OBJECT_TYPE pObject;
  357. PPERF_COUNTER_DEFINITION pCounterDef;
  358. PPERF_COUNTER_BLOCK pCounterBlock;
  359. UINT nSelObject, nSelInstance;
  360. TCHAR szTypeNameBuffer[MAX_PATH];
  361. TCHAR szDisplayBuffer [SMALL_BUFFER_SIZE];
  362. DWORD *pdwLoDword, *pdwHiDword;
  363. DWORD dwThisCounter;
  364. SendDlgItemMessage (hDlg, IDC_DATA_LIST, LB_RESETCONTENT, 0, 0);
  365. nSelObject = (UINT)SendDlgItemMessage (hDlg, IDC_OBJECT, CB_GETCURSEL, 0, 0);
  366. nSelInstance = (UINT)SendDlgItemMessage (hDlg, IDC_INSTANCE, CB_GETCURSEL, 0, 0);
  367. if ((nSelObject != CB_ERR) && (nSelInstance != CB_ERR)) {
  368. pObject = (PPERF_OBJECT_TYPE)SendDlgItemMessage (hDlg, IDC_OBJECT,
  369. CB_GETITEMDATA, (WPARAM)nSelObject, 0);
  370. pCounterBlock = (PPERF_COUNTER_BLOCK)SendDlgItemMessage (hDlg, IDC_INSTANCE,
  371. CB_GETITEMDATA, (WPARAM)nSelInstance, 0);
  372. pCounterDef = FirstCounter (pObject);
  373. for (dwThisCounter = 0; dwThisCounter < pObject->NumCounters; dwThisCounter++) {
  374. // get pointer to this counter's data (in this instance if applicable
  375. pdwLoDword = (PDWORD)((LPBYTE)pCounterBlock + pCounterDef->CounterOffset);
  376. pdwHiDword = pdwLoDword + 1;
  377. lstrcpy (szTypeNameBuffer, GetCounterTypeName (pCounterDef->CounterType));
  378. if (*szTypeNameBuffer == 0) {
  379. // no string returned so format data as HEX DWORD
  380. _stprintf (szTypeNameBuffer, (LPCTSTR)TEXT("Undefined Type: 0x%8.8x"),
  381. pCounterDef->CounterType);
  382. }
  383. if (pCounterDef->CounterSize <= sizeof(DWORD)) {
  384. _stprintf (szDisplayBuffer, (LPCTSTR)TEXT("%d\t%s\t%s\t0x%8.8x (%d)"),
  385. pCounterDef->CounterNameTitleIndex,
  386. (pCounterDef->CounterNameTitleIndex <= dwLastName ?
  387. szNameTable[pCounterDef->CounterNameTitleIndex] : (LPCTSTR)TEXT("Name not loaded")),
  388. szTypeNameBuffer,
  389. *pdwLoDword, *pdwLoDword);
  390. } else {
  391. _stprintf (szDisplayBuffer, (LPCTSTR)TEXT("%d\t%s\t%s\t0x%8.8x%8.8x"),
  392. pCounterDef->CounterNameTitleIndex,
  393. (pCounterDef->CounterNameTitleIndex <= dwLastName ?
  394. szNameTable[pCounterDef->CounterNameTitleIndex] : (LPCTSTR)TEXT("Name not loaded")),
  395. szTypeNameBuffer,
  396. *pdwHiDword, *pdwLoDword);
  397. }
  398. SendDlgItemMessage (hDlg, IDC_DATA_LIST, LB_INSERTSTRING,
  399. (WPARAM)-1, (LPARAM)szDisplayBuffer);
  400. pCounterDef = NextCounter(pCounterDef);
  401. }
  402. if (lDisplayIndex < 0) {
  403. if (pObject->DefaultCounter >= 0) {
  404. SendDlgItemMessage (hDlg, IDC_DATA_LIST, LB_SETCURSEL,
  405. (WPARAM)pObject->DefaultCounter, 0);
  406. } else {
  407. SendDlgItemMessage (hDlg, IDC_DATA_LIST, LB_SETCURSEL,
  408. (WPARAM)0, 0);
  409. }
  410. } else {
  411. SendDlgItemMessage (hDlg, IDC_DATA_LIST, LB_SETCURSEL,
  412. (WPARAM)lDisplayIndex, (LPARAM)0);
  413. }
  414. } else {
  415. // no object and/or instsance selected so nothing else to do
  416. }
  417. return TRUE;
  418. }
  419. static
  420. BOOL
  421. OnComputerChange (
  422. IN HWND hDlg
  423. )
  424. {
  425. TCHAR szLocalComputerName [MAX_COMPUTERNAME_LENGTH+3];
  426. HKEY hLocalMachineKey = NULL;
  427. HKEY hLocalPerfKey = NULL;
  428. LPWSTR *szLocalNameTable = NULL;
  429. BOOL bResult = FALSE;
  430. HWND hWndComputerName;
  431. SET_WAIT_CURSOR;
  432. // get name from edit control
  433. hWndComputerName = GetDlgItem (hDlg, IDC_COMPUTERNAME);
  434. GetWindowText (hWndComputerName,
  435. szLocalComputerName,
  436. MAX_COMPUTERNAME_LENGTH+2);
  437. if (lstrcmpi(szComputerName, szLocalComputerName) != 0) {
  438. // a new name has been entered so try to connect to it
  439. if (lstrcmpi(szLocalComputerName, szThisComputerName) == 0) {
  440. // then this is the local machine which is a special case
  441. hLocalMachineKey = HKEY_LOCAL_MACHINE;
  442. hLocalPerfKey = HKEY_PERFORMANCE_DATA;
  443. szLocalComputerName[0] = 0;
  444. } else {
  445. // try to connect to remote computer
  446. if (RegConnectRegistry (szLocalComputerName,
  447. HKEY_LOCAL_MACHINE, &hLocalMachineKey) == ERROR_SUCCESS) {
  448. // connected to the new machine, so Try to connect to
  449. // the performance data, too
  450. if (RegConnectRegistry (szLocalComputerName,
  451. HKEY_PERFORMANCE_DATA, &hLocalPerfKey) == ERROR_SUCCESS) {
  452. } else {
  453. DisplayMessageBox (hDlg,
  454. IDS_UNABLE_CONNECT_PERF,
  455. IDS_APP_ERROR, MB_OK);
  456. }
  457. } else {
  458. DisplayMessageBox (hDlg,
  459. IDS_UNABLE_CONNECT_MACH,
  460. IDS_APP_ERROR, MB_OK);
  461. }
  462. }
  463. if ((hLocalMachineKey != NULL) && (hLocalPerfKey != NULL)) {
  464. // try to get a new name table
  465. szLocalNameTable = BuildNameTable (
  466. (szLocalComputerName == 0 ? NULL : szLocalComputerName),
  467. NULL,
  468. &dwLastName);
  469. if (szLocalNameTable) {
  470. bResult = TRUE;
  471. } else {
  472. DisplayMessageBox (hDlg,
  473. IDS_UNABLE_GET_NAMES,
  474. IDS_APP_ERROR, MB_OK);
  475. }
  476. }
  477. if (bResult) {
  478. // made it so close the old connections
  479. if (hKeyMachine != NULL) {
  480. RegCloseKey (hKeyMachine);
  481. }
  482. hKeyMachine = hLocalMachineKey;
  483. if (hKeyPerformance != NULL) {
  484. RegCloseKey (hKeyPerformance);
  485. }
  486. hKeyPerformance = hLocalPerfKey;
  487. if (szNameTable != NULL) {
  488. MemoryFree (szNameTable);
  489. }
  490. szNameTable = szLocalNameTable;
  491. if (szLocalComputerName[0] == 0) {
  492. lstrcpy (szComputerName, szThisComputerName);
  493. }
  494. // then update the fields
  495. bResult = LoadObjectList (hDlg, NULL);
  496. if (bResult) {
  497. LoadInstanceList (hDlg, NULL);
  498. ShowCounterData (hDlg, -1);
  499. }
  500. } else {
  501. // unable to get info from machine so clean up
  502. if (hLocalPerfKey != NULL) RegCloseKey (hLocalPerfKey);
  503. if (hLocalMachineKey != NULL) RegCloseKey (hLocalMachineKey);
  504. if (szLocalNameTable != NULL) MemoryFree (szLocalNameTable);
  505. // reset computer name to the one that works.
  506. SetWindowText (hWndComputerName, szComputerName);
  507. }
  508. } else {
  509. // the name hasn't changed
  510. }
  511. return TRUE;
  512. }
  513. static
  514. BOOL
  515. MainDlg_WM_INITDIALOG (
  516. IN HWND hDlg,
  517. IN WPARAM wParam,
  518. IN LPARAM lParam
  519. )
  520. {
  521. DWORD dwComputerNameLength = MAX_COMPUTERNAME_LENGTH+1;
  522. UNREFERENCED_PARAMETER (lParam);
  523. UNREFERENCED_PARAMETER (wParam);
  524. SET_WAIT_CURSOR;
  525. lstrcpy (szThisComputerName, (LPCTSTR)TEXT("\\\\"));
  526. GetComputerName (szThisComputerName+2, &dwComputerNameLength);
  527. szComputerName[0] = 0; // reset the computer name
  528. // load the local machine name into the edit box
  529. SetWindowText (GetDlgItem (hDlg, IDC_COMPUTERNAME), szThisComputerName);
  530. SendDlgItemMessage (hDlg, IDC_DATA_LIST, LB_SETTABSTOPS,
  531. (WPARAM)NUM_TAB_STOPS, (LPARAM)&nDataListTabs);
  532. CheckDlgButton (hDlg, IDC_INCLUDE_COSTLY, UNCHECKED);
  533. OnComputerChange (hDlg);
  534. SetFocus (GetDlgItem (hDlg, IDC_OBJECT));
  535. SET_ARROW_CURSOR;
  536. return FALSE;
  537. }
  538. static
  539. BOOL
  540. MainDlg_IDC_COMPUTERNAME (
  541. IN HWND hDlg,
  542. IN WORD wNotifyMsg,
  543. IN HWND hWndControl
  544. )
  545. {
  546. UNREFERENCED_PARAMETER (hWndControl);
  547. switch (wNotifyMsg) {
  548. case EN_KILLFOCUS:
  549. OnComputerChange(hDlg);
  550. return TRUE;
  551. default:
  552. return FALSE;
  553. }
  554. }
  555. static
  556. BOOL
  557. MainDlg_IDC_OBJECT (
  558. IN HWND hDlg,
  559. IN WORD wNotifyMsg,
  560. IN HWND hWndControl
  561. )
  562. {
  563. UNREFERENCED_PARAMETER (hWndControl);
  564. switch (wNotifyMsg) {
  565. case CBN_SELCHANGE:
  566. SET_WAIT_CURSOR;
  567. if (pMainPerfData) {
  568. LoadInstanceList (hDlg, NULL);
  569. ShowCounterData (hDlg, -1);
  570. }
  571. SET_ARROW_CURSOR;
  572. return TRUE;
  573. default:
  574. return FALSE;
  575. }
  576. }
  577. static
  578. BOOL
  579. MainDlg_IDC_INSTANCE (
  580. IN HWND hDlg,
  581. IN WORD wNotifyMsg,
  582. IN HWND hWndControl
  583. )
  584. {
  585. UNREFERENCED_PARAMETER (hWndControl);
  586. switch (wNotifyMsg) {
  587. case CBN_SELCHANGE:
  588. SET_WAIT_CURSOR;
  589. ShowCounterData (hDlg, -1);
  590. SET_ARROW_CURSOR;
  591. return TRUE;
  592. default:
  593. return FALSE;
  594. }
  595. }
  596. static
  597. BOOL
  598. MainDlg_IDC_DATA_LIST (
  599. IN HWND hDlg,
  600. IN WORD wNotifyMsg,
  601. IN HWND hWndControl
  602. )
  603. {
  604. UNREFERENCED_PARAMETER (hWndControl);
  605. UNREFERENCED_PARAMETER (hDlg);
  606. switch (wNotifyMsg) {
  607. default:
  608. return FALSE;
  609. }
  610. }
  611. static
  612. BOOL
  613. MainDlg_IDC_REFRESH (
  614. IN HWND hDlg,
  615. IN WORD wNotifyMsg,
  616. IN HWND hWndControl
  617. )
  618. {
  619. TCHAR szSelObject[MAX_PATH];
  620. TCHAR szSelInstance[MAX_PATH];
  621. BOOL bResult;
  622. LONG lCounterIdx;
  623. UNREFERENCED_PARAMETER (hWndControl);
  624. switch (wNotifyMsg) {
  625. case BN_CLICKED:
  626. SET_WAIT_CURSOR;
  627. GetDlgItemText (hDlg, IDC_OBJECT,
  628. szSelObject, MAX_PATH-1);
  629. GetDlgItemText (hDlg, IDC_INSTANCE,
  630. szSelInstance, MAX_PATH-1);
  631. lCounterIdx = (ULONG)SendDlgItemMessage (hDlg, IDC_DATA_LIST,
  632. LB_GETCURSEL, 0, 0);
  633. bResult = LoadObjectList (hDlg, szSelObject);
  634. if (bResult) {
  635. LoadInstanceList (hDlg, szSelInstance);
  636. ShowCounterData (hDlg, lCounterIdx);
  637. }
  638. SET_ARROW_CURSOR;
  639. return TRUE;
  640. default:
  641. return FALSE;
  642. }
  643. }
  644. static
  645. BOOL
  646. MainDlg_IDC_ABOUT ()
  647. {
  648. TCHAR buffer[1024];
  649. TCHAR strProgram[1024];
  650. DWORD dw;
  651. BYTE* pVersionInfo;
  652. LPTSTR pVersion = NULL;
  653. LPTSTR pProduct = NULL;
  654. LPTSTR pCopyRight = NULL;
  655. dw = GetModuleFileName(NULL, strProgram, 1024 );
  656. if( dw>0 ){
  657. dw = GetFileVersionInfoSize( strProgram, &dw );
  658. if( dw > 0 ){
  659. pVersionInfo = (BYTE*)malloc(dw);
  660. if( NULL != pVersionInfo ){
  661. if(GetFileVersionInfo( strProgram, 0, dw, pVersionInfo )){
  662. LPDWORD lptr = NULL;
  663. VerQueryValue( pVersionInfo, _T("\\VarFileInfo\\Translation"), (void**)&lptr, (UINT*)&dw );
  664. if( lptr != NULL ){
  665. _stprintf( buffer, _T("\\StringFileInfo\\%04x%04x\\%s"), LOWORD(*lptr), HIWORD(*lptr), _T("ProductVersion") );
  666. VerQueryValue( pVersionInfo, buffer, (void**)&pVersion, (UINT*)&dw );
  667. _stprintf( buffer, _T("\\StringFileInfo\\%04x%04x\\%s"), LOWORD(*lptr), HIWORD(*lptr), _T("OriginalFilename") );
  668. VerQueryValue( pVersionInfo, buffer, (void**)&pProduct, (UINT*)&dw );
  669. _stprintf( buffer, _T("\\StringFileInfo\\%04x%04x\\%s"), LOWORD(*lptr), HIWORD(*lptr), _T("LegalCopyright") );
  670. VerQueryValue( pVersionInfo, buffer, (void**)&pCopyRight, (UINT*)&dw );
  671. }
  672. if( pProduct != NULL && pVersion != NULL && pCopyRight != NULL ){
  673. _stprintf( buffer, _T("\nMicrosoft (R) %s\nVersion: %s\n%s"), pProduct, pVersion, pCopyRight );
  674. }
  675. }
  676. free( pVersionInfo );
  677. }
  678. }
  679. }
  680. MessageBox( NULL, buffer, _T("About ShowPerf"), MB_OK );
  681. return TRUE;
  682. }
  683. static
  684. BOOL
  685. MainDlg_WM_COMMAND (
  686. IN HWND hDlg,
  687. IN WPARAM wParam,
  688. IN LPARAM lParam
  689. )
  690. {
  691. WORD wCtrlId, wNotifyMsg;
  692. HWND hWndControl;
  693. wCtrlId = GET_CONTROL_ID (wParam);
  694. wNotifyMsg = GET_NOTIFY_MSG (wParam, lParam);
  695. hWndControl = GET_COMMAND_WND (lParam);
  696. switch (wCtrlId) {
  697. case IDC_COMPUTERNAME:
  698. return MainDlg_IDC_COMPUTERNAME (hDlg, wNotifyMsg, hWndControl);
  699. case IDC_OBJECT:
  700. return MainDlg_IDC_OBJECT (hDlg, wNotifyMsg, hWndControl);
  701. case IDC_INSTANCE:
  702. return MainDlg_IDC_INSTANCE (hDlg, wNotifyMsg, hWndControl);
  703. case IDC_DATA_LIST:
  704. return MainDlg_IDC_DATA_LIST (hDlg, wNotifyMsg, hWndControl);
  705. case IDC_REFRESH:
  706. return MainDlg_IDC_REFRESH (hDlg, wNotifyMsg, hWndControl);
  707. case IDC_ABOUT:
  708. return MainDlg_IDC_ABOUT ();
  709. case IDOK:
  710. EndDialog (hDlg, IDOK);
  711. return TRUE;
  712. default:
  713. return FALSE;
  714. }
  715. }
  716. static
  717. BOOL
  718. MainDlg_WM_SYSCOMMAND (
  719. IN HWND hDlg,
  720. IN WPARAM wParam,
  721. IN LPARAM lParam
  722. )
  723. {
  724. UNREFERENCED_PARAMETER (lParam);
  725. switch (wParam) {
  726. case SC_CLOSE:
  727. EndDialog (hDlg, IDOK);
  728. return TRUE;
  729. default:
  730. return FALSE;
  731. }
  732. }
  733. static
  734. BOOL
  735. MainDlg_WM_CLOSE (
  736. IN HWND hDlg,
  737. IN WPARAM wParam,
  738. IN LPARAM lParam
  739. )
  740. {
  741. UNREFERENCED_PARAMETER (lParam);
  742. UNREFERENCED_PARAMETER (wParam);
  743. UNREFERENCED_PARAMETER (hDlg);
  744. MemoryFree (pMainPerfData);
  745. pMainPerfData = NULL;
  746. MemoryFree (szNameTable);
  747. szNameTable = NULL;
  748. return TRUE;
  749. }
  750. INT_PTR
  751. MainDlgProc (
  752. IN HWND hDlg,
  753. IN UINT message,
  754. IN WPARAM wParam,
  755. IN LPARAM lParam
  756. )
  757. {
  758. switch (message) {
  759. case WM_INITDIALOG:
  760. return MainDlg_WM_INITDIALOG (hDlg, wParam, lParam);
  761. case WM_COMMAND:
  762. return MainDlg_WM_COMMAND (hDlg, wParam, lParam);
  763. case WM_SYSCOMMAND:
  764. return MainDlg_WM_SYSCOMMAND (hDlg, wParam, lParam);
  765. case WM_CLOSE:
  766. return MainDlg_WM_CLOSE (hDlg, wParam, lParam);
  767. default:
  768. return FALSE;
  769. }
  770. }