|
|
1.1 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: ! 12: ! 13: /****************************************************************************** ! 14: ! 15: P R O C E S S V I E W E R ! 16: ! 17: Name: pviewer.c ! 18: ! 19: Description: ! 20: This program demonstrates the usage of special registry APIs ! 21: for collecting performance data. ! 22: ! 23: C files used in this app: ! 24: pviewer.c - this file ! 25: pviewdat.c - updates the dialog ! 26: objdata.c - access performance data objects ! 27: instdata.c - access performance data instances ! 28: cntrdata.c - access performance data counters ! 29: ! 30: ******************************************************************************/ ! 31: ! 32: ! 33: ! 34: ! 35: #include <windows.h> ! 36: #include <winperf.h> ! 37: #include "perfdata.h" ! 38: #include "pviewdat.h" ! 39: #include "pviewdlg.h" ! 40: #include <string.h> ! 41: #include <stdio.h> ! 42: ! 43: ! 44: ! 45: #define INDEX_STR_LEN 10 ! 46: #define MACHINE_NAME_LEN MAX_COMPUTERNAME_LENGTH+2 ! 47: #define MACHINE_NAME_SIZE MACHINE_NAME_LEN+1 ! 48: ! 49: ! 50: /**** ! 51: Globals ! 52: ****/ ! 53: ! 54: TCHAR INDEX_PROCTHRD_OBJ[2*INDEX_STR_LEN]; ! 55: TCHAR INDEX_COSTLY_OBJ[3*INDEX_STR_LEN]; ! 56: ! 57: TCHAR gszMachineName[MACHINE_NAME_SIZE]; ! 58: TCHAR gszCurrentMachine[MACHINE_NAME_SIZE]; ! 59: ! 60: DWORD gPerfDataSize = 50*1024; // start with 50K ! 61: PPERF_DATA gpPerfData; ! 62: ! 63: DWORD gCostlyDataSize = 100*1024; // start wiih 100K ! 64: PPERF_DATA gpCostlyData; ! 65: ! 66: ! 67: PPERF_OBJECT gpProcessObject; // pointer to process objects ! 68: PPERF_OBJECT gpThreadObject; // pointer to thread objects ! 69: PPERF_OBJECT gpThreadDetailsObject; // pointer to thread detail objects ! 70: PPERF_OBJECT gpAddressSpaceObject; // pointer to address space objects ! 71: PPERF_OBJECT gpImageObject; // pointer to image objects ! 72: ! 73: ! 74: HKEY ghPerfKey = HKEY_PERFORMANCE_DATA; // get perf data from this key ! 75: HKEY ghMachineKey = HKEY_LOCAL_MACHINE; // get title index from this key ! 76: ! 77: ! 78: HCURSOR ghCursor[2]; // 0 = arrow, 1 = hourglass ! 79: ! 80: HANDLE ghMemUpdateEvent; // to signal a refresh of mem stats ! 81: HANDLE ghMemUpdateMutex; // to restrict overlapping refreshes ! 82: ! 83: ! 84: ! 85: ! 86: /**** ! 87: Prototypes ! 88: ****/ ! 89: ! 90: BOOL CALLBACK PviewDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam); ! 91: void PviewDlgRefresh (HWND hWnd); ! 92: void PviewDlgRefreshCostlyData (HWND hPviewDlg); ! 93: void PviewDlgRefreshProcess (HWND hWnd); ! 94: void PviewDlgRefreshThread (HWND hWnd); ! 95: void PviewDlgRefreshCurSelProcess (HWND hWnd); ! 96: void PviewDlgRefreshCurSelThread (HWND hWnd); ! 97: WORD PviewDlgGetCurSelPriority (HWND hWnd); ! 98: BOOL PviewDlgChangePriority (HWND hWnd, DWORD wParam, WORD wItem); ! 99: BOOL PviewDlgTerminateProcess (HWND hPviewDlg); ! 100: ! 101: BOOL CALLBACK MemDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam); ! 102: void MemDlgUpdateThread (HWND hWnd); ! 103: void MemDlgRefresh (HWND hWnd, HWND hPviewDlg); ! 104: void MemDlgRefreshCurSelImage (HWND hMemDlg, HWND hPviewDlg); ! 105: ! 106: INT GetCurSelText (HWND hList, LPTSTR str); ! 107: DWORD GetCurSelData (HWND hWnd, DWORD dwList); ! 108: INT ReSelectText (HWND hList, INT StartIndex, LPTSTR str); ! 109: void SetPerfIndexes (HWND hWnd); ! 110: DWORD GetTitleIdx (HWND hWnd, LPTSTR TitleSz[], DWORD LastIndex, LPTSTR Name); ! 111: void SetListBoxTabStops (HWND hWnd); ! 112: void SetLocalMachine (void); ! 113: BOOL ConnectComputer (HWND hWnd); ! 114: void DisableControls (HWND hPviewDlg); ! 115: void EnableControls (HWND hPviewDlg); ! 116: ! 117: ! 118: ! 119: ! 120: //******************************************************** ! 121: // ! 122: // WinMain -- ! 123: // ! 124: // Build Up: create the program's dialog box, ! 125: // load the desired icons, enter the message ! 126: // loop. ! 127: // ! 128: // Tear Down: free up the memory allocated by the ! 129: // dialog box proc, and exit. ! 130: // ! 131: int WINAPI WinMain (HINSTANCE hInstance, ! 132: HINSTANCE hPrevInstance, ! 133: LPSTR lpCmdLine, ! 134: int nCmdShow) ! 135: { ! 136: HANDLE hWndDialog; ! 137: MSG msg; ! 138: ! 139: ! 140: // load our default cursors ! 141: // ! 142: ghCursor[0] = LoadCursor (0, IDC_ARROW); ! 143: ghCursor[1] = LoadCursor (0, IDC_WAIT); ! 144: ! 145: // open our dialog box ! 146: // ! 147: hWndDialog = CreateDialogParam (hInstance, ! 148: MAKEINTRESOURCE (PVIEW_DLG), ! 149: NULL, ! 150: (DLGPROC) PviewDlgProc, ! 151: (LONG)0); ! 152: ! 153: // associate the icon with our window ! 154: // ! 155: SetClassLong (hWndDialog, GCL_HICON, (LONG)LoadIcon(hInstance, TEXT("VIEWPICON")) ); ! 156: ! 157: ! 158: // the almighty Windows message loop: ! 159: // ! 160: while (GetMessage (&msg, NULL, 0, 0)) ! 161: if (!IsDialogMessage (hWndDialog, &msg)) ! 162: { ! 163: TranslateMessage (&msg); ! 164: DispatchMessage (&msg); ! 165: } ! 166: ! 167: // close up shop ! 168: // ! 169: DestroyWindow (hWndDialog); ! 170: LocalFree (gpPerfData); ! 171: ! 172: return 0; ! 173: } ! 174: ! 175: ! 176: ! 177: ! 178: /***************** ! 179: PviewDlg functions ! 180: *****************/ ! 181: ! 182: //******************************************************** ! 183: // ! 184: // PviewDlgProc -- ! 185: // ! 186: // Pview dialog procedure ! 187: // ! 188: BOOL CALLBACK PviewDlgProc (HWND hWnd, ! 189: UINT wMsg, ! 190: WPARAM wParam, ! 191: LPARAM lParam) ! 192: { ! 193: WORD wItem; ! 194: ! 195: ! 196: switch (wMsg) ! 197: { ! 198: ! 199: case WM_INITDIALOG: ! 200: SetListBoxTabStops (hWnd); ! 201: SendDlgItemMessage (hWnd, PVIEW_COMPUTER, EM_LIMITTEXT, MACHINE_NAME_LEN, 0); ! 202: PostMessage (hWnd, WM_COMMAND, PVIEW_REFRESH, 0); ! 203: break; ! 204: ! 205: case WM_CLOSE: ! 206: PostQuitMessage (0); ! 207: break; ! 208: ! 209: case WM_COMMAND: ! 210: // ! 211: // handle our app-specific controls: ! 212: // ! 213: switch (LOWORD (wParam)) ! 214: { ! 215: // works just like "close" ! 216: // ! 217: case PVIEW_EXIT: ! 218: PostQuitMessage (0); ! 219: break; ! 220: ! 221: // if somebody moved the highlight in the thread list, ! 222: // update the view ! 223: // ! 224: case PVIEW_THREAD_LIST: ! 225: if (HIWORD(wParam) == LBN_DBLCLK || HIWORD(wParam) == LBN_SELCHANGE) ! 226: { ! 227: PviewDlgRefreshCurSelThread (hWnd); ! 228: PostMessage (hWnd, WM_COMMAND, PVIEW_REFRESH_COSTLY_DATA, 0); ! 229: } ! 230: break; ! 231: ! 232: // if somebody clicked on a new process, update all of the ! 233: // affected information. ! 234: // ! 235: case PVIEW_PROCESS_LIST: ! 236: if (HIWORD(wParam) == CBN_DBLCLK || HIWORD(wParam) == CBN_SELCHANGE) ! 237: { ! 238: PviewDlgRefreshCurSelProcess (hWnd); ! 239: PostMessage (hWnd, WM_COMMAND, PVIEW_REFRESH_COSTLY_DATA, 0); ! 240: if (HIWORD(wParam) == CBN_DBLCLK) ! 241: PostMessage (hWnd, WM_COMMAND, PVIEW_MEMORY_DETAIL, 0); ! 242: } ! 243: break; ! 244: ! 245: // the user wishes to view the memory stats in detail: ! 246: // ! 247: case PVIEW_MEMORY_DETAIL: ! 248: // ! 249: // check to see if we can get exclusive access ! 250: // to the memory statistics ! 251: // ! 252: if (WaitForSingleObject (ghMemUpdateMutex, 0)) ! 253: ! 254: // we can't, so just return. ! 255: // ! 256: return FALSE; ! 257: ! 258: else ! 259: { ! 260: // we have exclusive access, so start up the ! 261: // memory statistics dialog. ! 262: // ! 263: // release the mutex first so the dialog can use it. ! 264: // ! 265: ReleaseMutex (ghMemUpdateMutex); ! 266: DialogBoxParam (NULL, ! 267: MAKEINTRESOURCE (MEMORY_DLG), ! 268: hWnd, ! 269: (DLGPROC) MemDlgProc, ! 270: (LONG)hWnd); ! 271: } ! 272: break; ! 273: ! 274: // somebody clicked one of the priority radio ! 275: // buttons. Find out which one was selected... ! 276: // ! 277: case PVIEW_PRIORITY_HIGH: ! 278: case PVIEW_PRIORITY_NORMAL: ! 279: case PVIEW_PRIORITY_IDL: ! 280: if (SendDlgItemMessage (hWnd, PVIEW_PRIORITY_HIGH, BM_GETCHECK, 0, 0)) ! 281: wItem = PVIEW_PRIORITY_HIGH; ! 282: else if (SendDlgItemMessage (hWnd, PVIEW_PRIORITY_NORMAL, BM_GETCHECK, 0, 0)) ! 283: wItem = PVIEW_PRIORITY_NORMAL; ! 284: else ! 285: wItem = PVIEW_PRIORITY_IDL; ! 286: ! 287: // if the user actually clicked on a NEW state, ! 288: // do the change. ! 289: // ! 290: if (LOWORD(wParam) != wItem) ! 291: { ! 292: // of course, if it's a remote machine, disallow ! 293: // the modification. ! 294: // ! 295: if (lstrcmp (gszCurrentMachine, gszMachineName)) ! 296: { ! 297: SendDlgItemMessage (hWnd, wItem, BM_SETCHECK, 1, 0); ! 298: SetFocus (GetDlgItem (hWnd, wItem)); ! 299: MessageBox (hWnd, ! 300: TEXT("Cannot change process priority on remote machine"), ! 301: TEXT("Set priority"), ! 302: MB_ICONEXCLAMATION|MB_OK); ! 303: } ! 304: ! 305: // at this point, we know we are affecting the local ! 306: // machine, and a change has to be made. ! 307: // Just Do It(TM). ! 308: // ! 309: else if (PviewDlgChangePriority (hWnd, wParam, wItem)) ! 310: PviewDlgRefresh (hWnd); ! 311: ! 312: } ! 313: break; ! 314: ! 315: case PVIEW_THREAD_HIGHEST: ! 316: case PVIEW_THREAD_ABOVE: ! 317: case PVIEW_THREAD_NORMAL: ! 318: case PVIEW_THREAD_BELOW: ! 319: case PVIEW_THREAD_LOWEST: ! 320: // ! 321: // this selection hasn't been fleshed out yet. ! 322: // ! 323: PviewDlgRefreshCurSelThread (hWnd); ! 324: break; ! 325: ! 326: // terminate the selected process ! 327: // ! 328: case PVIEW_TERMINATE: ! 329: if (PviewDlgTerminateProcess (hWnd)) ! 330: PviewDlgRefresh (hWnd); ! 331: break; ! 332: ! 333: // if the text has changed, we want to connect and ! 334: // view another system's processes... ! 335: // ! 336: case PVIEW_COMPUTER: ! 337: if (HIWORD(wParam) == EN_CHANGE) ! 338: EnableWindow (GetDlgItem (hWnd, PVIEW_CONNECT), TRUE); ! 339: else ! 340: return FALSE; ! 341: break; ! 342: ! 343: // we were told to connect, go ahead and try... ! 344: // ! 345: case PVIEW_CONNECT: ! 346: if (ConnectComputer (hWnd)) ! 347: { ! 348: SetPerfIndexes (hWnd); ! 349: PviewDlgRefresh (hWnd); ! 350: } ! 351: break; ! 352: ! 353: // refresh the current information displayed ! 354: // ! 355: case PVIEW_REFRESH: ! 356: if (ConnectComputer (hWnd)) ! 357: SetPerfIndexes (hWnd); ! 358: PviewDlgRefresh (hWnd); ! 359: break; ! 360: ! 361: // refresh the currently updated costly ! 362: // statistics ! 363: // ! 364: case PVIEW_REFRESH_COSTLY_DATA: ! 365: if (WaitForSingleObject (ghMemUpdateMutex, 0)) ! 366: return FALSE; ! 367: ! 368: PviewDlgRefreshCostlyData (hWnd); ! 369: ReleaseMutex (ghMemUpdateMutex); ! 370: break; ! 371: ! 372: default: ! 373: return FALSE; ! 374: } ! 375: break; ! 376: ! 377: default: ! 378: return FALSE; ! 379: } ! 380: ! 381: return TRUE; ! 382: } ! 383: ! 384: ! 385: ! 386: ! 387: //******************************************************** ! 388: // ! 389: // PviewDlgRefresh -- ! 390: // ! 391: // Refresh the pview dialog. ! 392: // ! 393: void PviewDlgRefresh (HWND hWnd) ! 394: { ! 395: static HANDLE hMemUpdateThread = NULL; ! 396: static DWORD MemUpdateThreadID; ! 397: ! 398: ! 399: SetCursor (ghCursor[1]); ! 400: ! 401: ! 402: if (hMemUpdateThread) // get memory data ! 403: SetEvent (ghMemUpdateEvent); ! 404: else ! 405: hMemUpdateThread = CreateThread (NULL, ! 406: 0, ! 407: (LPTHREAD_START_ROUTINE)MemDlgUpdateThread, ! 408: (LPVOID)hWnd, ! 409: 0, ! 410: &MemUpdateThreadID); ! 411: ! 412: ! 413: // get performance data ! 414: // ! 415: gpPerfData = RefreshPerfData (ghPerfKey, INDEX_PROCTHRD_OBJ, gpPerfData, &gPerfDataSize); ! 416: ! 417: gpProcessObject = FindObject (gpPerfData, PX_PROCESS); ! 418: gpThreadObject = FindObject (gpPerfData, PX_THREAD); ! 419: ! 420: ! 421: // refresh ! 422: // ! 423: PviewDlgRefreshProcess (hWnd); ! 424: PviewDlgRefreshThread (hWnd); ! 425: ! 426: SetCursor (ghCursor[0]); ! 427: ! 428: } ! 429: ! 430: ! 431: ! 432: ! 433: //******************************************************** ! 434: // ! 435: // PviewDlgRefreshCostlyData -- ! 436: // ! 437: // Refresh the costly data. ! 438: // ! 439: void PviewDlgRefreshCostlyData (HWND hPviewDlg) ! 440: { ! 441: LPTSTR szProcessName; ! 442: LPTSTR szThreadName; ! 443: PPERF_INSTANCE pInstance; ! 444: DWORD dwIndex; ! 445: ! 446: ! 447: dwIndex = GetCurSelData (hPviewDlg, PVIEW_PROCESS_LIST); ! 448: pInstance = FindInstanceN (gpProcessObject, dwIndex); ! 449: szProcessName = InstanceName (pInstance); ! 450: ! 451: RefreshPviewDlgMemoryData (hPviewDlg, ! 452: pInstance, ! 453: gpProcessObject, ! 454: gpAddressSpaceObject); ! 455: ! 456: ! 457: dwIndex = GetCurSelData (hPviewDlg, PVIEW_THREAD_LIST); ! 458: pInstance = FindInstanceN (gpThreadObject, dwIndex); ! 459: szThreadName = InstanceName (pInstance); ! 460: ! 461: RefreshPviewDlgThreadPC (hPviewDlg, ! 462: szProcessName, ! 463: szThreadName, ! 464: gpThreadDetailsObject, ! 465: gpCostlyData); ! 466: ! 467: } ! 468: ! 469: ! 470: ! 471: ! 472: //******************************************************** ! 473: // ! 474: // PviewDlgRefreshProcess -- ! 475: // ! 476: // Refresh the process list and data in pview dialog. ! 477: // ! 478: void PviewDlgRefreshProcess (HWND hWnd) ! 479: { ! 480: TCHAR szProcessString[256]; ! 481: INT nProcess; ! 482: INT nIndex; ! 483: HWND hProcessList; ! 484: DWORD dwProcessIndex; ! 485: ! 486: ! 487: // refresh process list ! 488: // ! 489: hProcessList = GetDlgItem (hWnd, PVIEW_PROCESS_LIST); ! 490: nProcess = GetCurSelText (hProcessList, szProcessString); ! 491: ! 492: SendMessage (hProcessList, WM_SETREDRAW, FALSE, 0); ! 493: SendMessage (hProcessList, LB_RESETCONTENT, 0, 0); ! 494: SendMessage (hProcessList, LB_SETITEMDATA, 0, 0); ! 495: ! 496: ! 497: RefreshProcessList (hProcessList, gpProcessObject); ! 498: ! 499: // refresh process data ! 500: // ! 501: if (nProcess != LB_ERR) ! 502: nIndex = ReSelectText (hProcessList, nProcess, szProcessString); ! 503: else ! 504: nIndex = 0; ! 505: ! 506: ! 507: dwProcessIndex = SendMessage (hProcessList, LB_GETITEMDATA, nIndex, 0); ! 508: ! 509: RefreshProcessData (hWnd, gpProcessObject, dwProcessIndex); ! 510: ! 511: SendMessage (hProcessList, WM_SETREDRAW, TRUE, 0); ! 512: ! 513: } ! 514: ! 515: ! 516: ! 517: ! 518: //******************************************************** ! 519: // ! 520: // PviewDlgRefreshThread -- ! 521: // ! 522: // Refresh the thread list and data in pview dialog. ! 523: // ! 524: void PviewDlgRefreshThread (HWND hWnd) ! 525: { ! 526: TCHAR szThreadString[256]; ! 527: INT nThread; ! 528: INT nIndex; ! 529: HWND hThreadList; ! 530: DWORD dwThreadIndex; ! 531: ! 532: PPERF_INSTANCE pProcessInstance; ! 533: DWORD dwProcessIndex; ! 534: ! 535: ! 536: // get process info ! 537: // ! 538: dwProcessIndex = GetCurSelData (hWnd, PVIEW_PROCESS_LIST); ! 539: pProcessInstance = FindInstanceN (gpProcessObject, dwProcessIndex); ! 540: ! 541: ! 542: // refresh thread list ! 543: // ! 544: hThreadList = GetDlgItem (hWnd, PVIEW_THREAD_LIST); ! 545: nThread = GetCurSelText (hThreadList, szThreadString); ! 546: ! 547: SendMessage (hThreadList, WM_SETREDRAW, FALSE, 0); ! 548: SendMessage (hThreadList, LB_RESETCONTENT, 0, 0); ! 549: SendMessage (hThreadList, LB_SETITEMDATA, 0, 0); ! 550: ! 551: RefreshThreadList (hThreadList, gpThreadObject, dwProcessIndex); ! 552: ! 553: ! 554: // refresh thread data ! 555: // ! 556: if (nThread != LB_ERR) ! 557: nIndex = ReSelectText (hThreadList, nThread, szThreadString); ! 558: else ! 559: nIndex = 0; ! 560: ! 561: dwThreadIndex = SendMessage (hThreadList, LB_GETITEMDATA, nIndex, 0); ! 562: ! 563: RefreshThreadData (hWnd, ! 564: gpThreadObject, ! 565: dwThreadIndex, ! 566: gpProcessObject, ! 567: pProcessInstance); ! 568: ! 569: SendMessage (hThreadList, WM_SETREDRAW, TRUE, 0); ! 570: ! 571: } ! 572: ! 573: ! 574: ! 575: ! 576: //******************************************************** ! 577: // ! 578: // PviewDlgGetCurSelPriority -- ! 579: // ! 580: // Get the process priority of currently selected process. ! 581: // ! 582: WORD PviewDlgGetCurSelPriority (HWND hWnd) ! 583: { ! 584: DWORD dwIndex; ! 585: PPERF_INSTANCE pInst; ! 586: ! 587: dwIndex = GetCurSelData (hWnd, PVIEW_PROCESS_LIST); ! 588: pInst = FindInstanceN (gpProcessObject, dwIndex); ! 589: return ProcessPriority (gpProcessObject, pInst); ! 590: } ! 591: ! 592: ! 593: ! 594: ! 595: //******************************************************** ! 596: // ! 597: // PviewDlgRefreshCurSelProcess -- ! 598: // ! 599: // Refresh the data of currently selected process. ! 600: // ! 601: void PviewDlgRefreshCurSelProcess (HWND hWnd) ! 602: { ! 603: DWORD dwIndex; ! 604: ! 605: dwIndex = GetCurSelData (hWnd, PVIEW_PROCESS_LIST); ! 606: RefreshProcessData (hWnd, gpProcessObject, dwIndex); ! 607: ! 608: PviewDlgRefreshThread (hWnd); ! 609: } ! 610: ! 611: ! 612: ! 613: ! 614: //******************************************************** ! 615: // ! 616: // PviewDlgRefreshCurSelThread -- ! 617: // ! 618: // Refresh the data of currently selected thread. ! 619: // ! 620: void PviewDlgRefreshCurSelThread (HWND hWnd) ! 621: { ! 622: PPERF_INSTANCE pProcessInstance; ! 623: DWORD dwIndex; ! 624: ! 625: dwIndex = GetCurSelData (hWnd, PVIEW_PROCESS_LIST); ! 626: pProcessInstance = FindInstanceN (gpProcessObject, dwIndex); ! 627: ! 628: dwIndex = GetCurSelData (hWnd, PVIEW_THREAD_LIST); ! 629: ! 630: RefreshThreadData (hWnd, ! 631: gpThreadObject, ! 632: dwIndex, ! 633: gpProcessObject, ! 634: pProcessInstance); ! 635: } ! 636: ! 637: ! 638: ! 639: ! 640: //******************************************************** ! 641: // ! 642: // PviewDlgChangePriority -- ! 643: // ! 644: // Change process priority. ! 645: // ! 646: BOOL PviewDlgChangePriority (HWND hWnd, DWORD wParam, WORD wItem) ! 647: { ! 648: DWORD dwIndex; ! 649: PPERF_INSTANCE pInst; ! 650: PPERF_COUNTER pCountID; ! 651: DWORD *pProcessID; ! 652: DWORD ProcessID; ! 653: HANDLE hProcess; ! 654: BOOL bStat; ! 655: ! 656: ! 657: ! 658: dwIndex = GetCurSelData (hWnd, PVIEW_PROCESS_LIST); ! 659: pInst = FindInstanceN (gpProcessObject, dwIndex); ! 660: ! 661: ! 662: if (pCountID = FindCounter (gpProcessObject, PX_PROCESS_ID)) ! 663: { ! 664: pProcessID = (DWORD *) CounterData (pInst, pCountID); ! 665: ProcessID = *pProcessID; ! 666: } ! 667: else ! 668: { ! 669: SendDlgItemMessage (hWnd, wItem, BM_SETCHECK, 1, 0); ! 670: SetFocus (GetDlgItem (hWnd, wItem)); ! 671: MessageBox (hWnd, ! 672: TEXT("Cannot find ID for this process"), ! 673: TEXT("Set priority"), ! 674: MB_ICONEXCLAMATION|MB_OK); ! 675: return FALSE; ! 676: } ! 677: ! 678: ! 679: hProcess = OpenProcess (PROCESS_SET_INFORMATION, FALSE, ProcessID); ! 680: if (!hProcess) ! 681: { ! 682: SendDlgItemMessage (hWnd, wItem, BM_SETCHECK, 1, 0); ! 683: SetFocus (GetDlgItem (hWnd, wItem)); ! 684: MessageBox (hWnd, ! 685: TEXT("Unable to open the process; Priority not changed"), ! 686: TEXT("Set priority"), ! 687: MB_ICONEXCLAMATION|MB_OK); ! 688: return FALSE; ! 689: } ! 690: ! 691: ! 692: ! 693: switch (wParam) ! 694: { ! 695: case PVIEW_PRIORITY_HIGH: ! 696: bStat = SetPriorityClass (hProcess, HIGH_PRIORITY_CLASS); ! 697: break; ! 698: ! 699: case PVIEW_PRIORITY_NORMAL: ! 700: bStat = SetPriorityClass (hProcess, NORMAL_PRIORITY_CLASS); ! 701: break; ! 702: ! 703: case PVIEW_PRIORITY_IDL: ! 704: bStat = SetPriorityClass (hProcess, IDLE_PRIORITY_CLASS); ! 705: break; ! 706: ! 707: default: ! 708: break; ! 709: } ! 710: ! 711: ! 712: CloseHandle (hProcess); ! 713: ! 714: if (!bStat) ! 715: { ! 716: SendDlgItemMessage (hWnd, wItem, BM_SETCHECK, 1, 0); ! 717: SetFocus (GetDlgItem (hWnd, wItem)); ! 718: MessageBox (hWnd, ! 719: TEXT("Unable to change priority"), ! 720: TEXT("Set priority"), ! 721: MB_ICONEXCLAMATION|MB_OK); ! 722: return FALSE; ! 723: } ! 724: ! 725: ! 726: return TRUE; ! 727: ! 728: } ! 729: ! 730: ! 731: ! 732: ! 733: //******************************************************** ! 734: // ! 735: // PviewDlgTerminateProcess -- ! 736: // ! 737: // Terminate the current selected process. ! 738: // ! 739: BOOL PviewDlgTerminateProcess (HWND hPviewDlg) ! 740: { ! 741: DWORD dwIndex; ! 742: PPERF_INSTANCE pInst; ! 743: PPERF_COUNTER pCountID; ! 744: DWORD *pProcessID; ! 745: DWORD ProcessID; ! 746: HANDLE hProcess; ! 747: TCHAR szTemp[50]; ! 748: ! 749: ! 750: dwIndex = GetCurSelData (hPviewDlg, PVIEW_PROCESS_LIST); ! 751: pInst = FindInstanceN (gpProcessObject, dwIndex); ! 752: ! 753: ! 754: if (pCountID = FindCounter (gpProcessObject, PX_PROCESS_ID)) ! 755: { ! 756: pProcessID = (DWORD *) CounterData (pInst, pCountID); ! 757: ProcessID = *pProcessID; ! 758: } ! 759: else ! 760: { ! 761: MessageBox (hPviewDlg, ! 762: TEXT("Cannot find ID for this process"), ! 763: TEXT("Terminate Process"), ! 764: MB_ICONEXCLAMATION|MB_OK); ! 765: return FALSE; ! 766: } ! 767: ! 768: ! 769: wsprintf (szTemp, TEXT("Terminate process %s (ID %#x)?"), ! 770: InstanceName (pInst), ProcessID); ! 771: ! 772: if (MessageBox (hPviewDlg, szTemp, TEXT("Terminate Process"), MB_ICONSTOP|MB_OKCANCEL) != IDOK) ! 773: return FALSE; ! 774: ! 775: ! 776: hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, ProcessID); ! 777: if (!hProcess) ! 778: { ! 779: MessageBox (hPviewDlg, ! 780: TEXT("Unable to open the process; Process not terminated"), ! 781: TEXT("Terminate Process"), ! 782: MB_ICONEXCLAMATION|MB_OK); ! 783: return FALSE; ! 784: } ! 785: ! 786: ! 787: if (!TerminateProcess (hProcess, 99)) ! 788: { ! 789: MessageBox (hPviewDlg, ! 790: TEXT("Unable to terminate the process."), ! 791: TEXT("Terminate Process"), ! 792: MB_ICONEXCLAMATION|MB_OK); ! 793: ! 794: CloseHandle (hProcess); ! 795: return FALSE; ! 796: } ! 797: ! 798: ! 799: CloseHandle (hProcess); ! 800: ! 801: return TRUE; ! 802: ! 803: } ! 804: ! 805: ! 806: ! 807: ! 808: /*************** ! 809: MemDlg functions ! 810: ***************/ ! 811: ! 812: //******************************************************** ! 813: // ! 814: // MemDlgProc -- ! 815: // ! 816: // MemoryDlg procedure ! 817: // ! 818: BOOL CALLBACK MemDlgProc (HWND hWnd, ! 819: UINT wMsg, ! 820: WPARAM wParam, ! 821: LPARAM lParam) ! 822: { ! 823: static HWND hPviewDlg; ! 824: ! 825: ! 826: switch (wMsg) ! 827: { ! 828: case WM_INITDIALOG: ! 829: hPviewDlg = (HWND)lParam; ! 830: PostMessage (hWnd, WM_COMMAND, MEMORY_REFRESH, 0); ! 831: break; ! 832: ! 833: case WM_QUIT: ! 834: case WM_CLOSE: ! 835: EndDialog (hWnd, TRUE); ! 836: break; ! 837: ! 838: case WM_COMMAND: ! 839: switch (LOWORD (wParam)) ! 840: { ! 841: // get the memory statistics for the currently selected ! 842: // process/thread ! 843: // ! 844: case MEMORY_IMAGE: ! 845: if (HIWORD(wParam) == CBN_DBLCLK || HIWORD(wParam) == CBN_SELCHANGE) ! 846: { ! 847: if (WaitForSingleObject (ghMemUpdateMutex, 0)) ! 848: return FALSE; ! 849: ! 850: MemDlgRefreshCurSelImage (hWnd, hPviewDlg); ! 851: ReleaseMutex (ghMemUpdateMutex); ! 852: } ! 853: else ! 854: return FALSE; ! 855: break; ! 856: ! 857: // refresh the current memory statistics, ! 858: // retry if we can't get the mutex ! 859: // ! 860: case MEMORY_REFRESH: ! 861: if (WaitForSingleObject (ghMemUpdateMutex, 1000)) ! 862: { ! 863: // can't get the mutex, retry... ! 864: // ! 865: PostMessage (hWnd, WM_COMMAND, MEMORY_REFRESH, 0); ! 866: return FALSE; ! 867: } ! 868: ! 869: MemDlgRefresh (hWnd, hPviewDlg); ! 870: ReleaseMutex (ghMemUpdateMutex); ! 871: break; ! 872: ! 873: case IDCANCEL: ! 874: case IDOK: ! 875: EndDialog (hWnd, TRUE); ! 876: break; ! 877: ! 878: default: ! 879: return FALSE; ! 880: } ! 881: default: ! 882: return FALSE; ! 883: } ! 884: ! 885: ! 886: return TRUE; ! 887: ! 888: } ! 889: ! 890: ! 891: ! 892: ! 893: //******************************************************** ! 894: // ! 895: // MemDlgUpdateThread -- ! 896: // ! 897: // This function runs in a separate thread to collect memory data. ! 898: // ! 899: void MemDlgUpdateThread (HWND hPviewDlg) ! 900: { ! 901: ! 902: ghMemUpdateMutex = CreateMutex (NULL, TRUE, NULL); ! 903: ghMemUpdateEvent = CreateEvent (NULL, FALSE, FALSE, NULL); ! 904: ! 905: ! 906: while (TRUE) ! 907: { ! 908: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_MEMORY_DETAIL), FALSE); ! 909: ! 910: ! 911: gpCostlyData = RefreshPerfData (ghPerfKey, ! 912: INDEX_COSTLY_OBJ, ! 913: gpCostlyData, ! 914: &gCostlyDataSize); ! 915: ! 916: ! 917: gpAddressSpaceObject = FindObject (gpCostlyData, PX_PROCESS_ADDRESS_SPACE); ! 918: gpThreadDetailsObject = FindObject (gpCostlyData, PX_THREAD_DETAILS); ! 919: gpImageObject = FindObject (gpCostlyData, PX_IMAGE); ! 920: ! 921: ! 922: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_MEMORY_DETAIL), TRUE); ! 923: ! 924: ReleaseMutex (ghMemUpdateMutex); ! 925: ! 926: PostMessage (hPviewDlg, WM_COMMAND, PVIEW_REFRESH_COSTLY_DATA, 0); ! 927: ! 928: ! 929: WaitForSingleObject (ghMemUpdateEvent, INFINITE); ! 930: WaitForSingleObject (ghMemUpdateMutex, INFINITE); ! 931: } ! 932: ! 933: } ! 934: ! 935: ! 936: ! 937: ! 938: //******************************************************** ! 939: // ! 940: // MemDlgRefresh -- ! 941: // ! 942: // Refresh the memory dialog. ! 943: // ! 944: void MemDlgRefresh (HWND hMemDlg, HWND hPviewDlg) ! 945: { ! 946: HWND hImageList; ! 947: DWORD dwIndex; ! 948: BOOL bStat; ! 949: PPERF_INSTANCE pInstance; ! 950: ! 951: ! 952: hImageList = GetDlgItem (hMemDlg, MEMORY_IMAGE); ! 953: ! 954: SendMessage (hImageList, WM_SETREDRAW, FALSE, 0); ! 955: SendMessage (hImageList, CB_RESETCONTENT, 0, 0); ! 956: SendMessage (hImageList, CB_SETITEMDATA, 0, 0); ! 957: ! 958: dwIndex = GetCurSelData (hPviewDlg, PVIEW_PROCESS_LIST); ! 959: pInstance = FindInstanceN (gpProcessObject, dwIndex); ! 960: ! 961: bStat = RefreshMemoryDlg (hMemDlg, ! 962: pInstance, ! 963: gpProcessObject, ! 964: gpAddressSpaceObject, ! 965: gpImageObject); ! 966: ! 967: SendMessage (hImageList, WM_SETREDRAW, TRUE, 0); ! 968: SendMessage (hImageList, CB_SETCURSEL, 0, 0); ! 969: ! 970: if (!bStat) ! 971: { ! 972: MessageBox (hMemDlg, ! 973: TEXT("Unable to retrieve memory detail"), ! 974: TEXT("Memory detail"), ! 975: MB_ICONSTOP|MB_OK); ! 976: PostMessage (hMemDlg, WM_CLOSE, 0, 0); ! 977: } ! 978: ! 979: } ! 980: ! 981: ! 982: ! 983: ! 984: //******************************************************** ! 985: // ! 986: // MemDlgRefreshCurSelImage -- ! 987: // ! 988: // Refresh the current selected image for memory dialog. ! 989: // ! 990: void MemDlgRefreshCurSelImage (HWND hMemDlg, HWND hPviewDlg) ! 991: { ! 992: HWND hList; ! 993: INT nIndex; ! 994: DWORD dwIndex; ! 995: ! 996: ! 997: hList = GetDlgItem (hMemDlg, MEMORY_IMAGE); ! 998: nIndex = SendMessage (hList, CB_GETCURSEL, 0, 0); ! 999: ! 1000: if (nIndex == CB_ERR) ! 1001: nIndex = 0; ! 1002: ! 1003: dwIndex = SendMessage (hList, CB_GETITEMDATA, nIndex, 0); ! 1004: ! 1005: if (dwIndex == 0xFFFFFFFF) ! 1006: MemDlgRefresh (hMemDlg, hPviewDlg); ! 1007: else ! 1008: RefreshMemoryDlgImage (hMemDlg, dwIndex, gpImageObject); ! 1009: ! 1010: } ! 1011: ! 1012: ! 1013: ! 1014: ! 1015: /**************** ! 1016: utility functions ! 1017: ****************/ ! 1018: ! 1019: //******************************************************** ! 1020: // ! 1021: // GetCurSelText -- ! 1022: // ! 1023: // Get the text of current selection. Used for later ReSelectText(). ! 1024: // ! 1025: INT GetCurSelText (HWND hList, LPTSTR str) ! 1026: { ! 1027: INT Index; ! 1028: INT Length; ! 1029: ! 1030: Index = SendMessage (hList, LB_GETCURSEL, 0, 0); ! 1031: Length = SendMessage (hList, LB_GETTEXT, Index, (DWORD)str); ! 1032: ! 1033: return Index; ! 1034: } ! 1035: ! 1036: ! 1037: ! 1038: ! 1039: //******************************************************** ! 1040: // ! 1041: // GetCurSelData -- ! 1042: // ! 1043: // Get the data associated with the current selection. ! 1044: // ! 1045: DWORD GetCurSelData (HWND hWnd, DWORD dwList) ! 1046: { ! 1047: HWND hList; ! 1048: INT nIndex; ! 1049: DWORD dwIndex; ! 1050: ! 1051: ! 1052: hList = GetDlgItem (hWnd, dwList); ! 1053: nIndex = SendMessage (hList, LB_GETCURSEL, 0, 0); ! 1054: ! 1055: if (nIndex == LB_ERR) ! 1056: nIndex = 0; ! 1057: ! 1058: dwIndex = SendMessage (hList, LB_GETITEMDATA, nIndex, 0); ! 1059: ! 1060: return dwIndex; ! 1061: } ! 1062: ! 1063: ! 1064: ! 1065: ! 1066: //******************************************************** ! 1067: // ! 1068: // ReSelectText -- ! 1069: // ! 1070: // Reselect the line specified by str. Returns the new index. If cannot ! 1071: // find the line or any error, then 0 is returned. ! 1072: // ! 1073: INT ReSelectText (HWND hList, INT StartIndex, LPTSTR str) ! 1074: { ! 1075: INT Index; ! 1076: INT Length; ! 1077: TCHAR SaveChar = TEXT('\0'); ! 1078: ! 1079: ! 1080: Index = SendMessage (hList, LB_FINDSTRING, StartIndex, (DWORD)str); ! 1081: ! 1082: if (Index == LB_ERR) ! 1083: { ! 1084: Length = lstrlen (str); ! 1085: ! 1086: while (Index == LB_ERR && Length) ! 1087: { ! 1088: SaveChar = str[Length-1]; ! 1089: str[Length-1] = TEXT('\0'); ! 1090: ! 1091: Index = SendMessage (hList, LB_FINDSTRING, StartIndex, (DWORD)str); ! 1092: ! 1093: str[Length-1] = SaveChar; ! 1094: Length--; ! 1095: } ! 1096: } ! 1097: ! 1098: if (Index == LB_ERR) ! 1099: return 0; ! 1100: else ! 1101: { ! 1102: SendMessage (hList, LB_SETCURSEL, Index, 0); ! 1103: return Index; ! 1104: } ! 1105: ! 1106: } ! 1107: ! 1108: ! 1109: ! 1110: ! 1111: //******************************************************** ! 1112: // ! 1113: // SetPerfIndexes ! 1114: // ! 1115: // Setup the perf data indexes. ! 1116: // ! 1117: void SetPerfIndexes (HWND hWnd) ! 1118: { ! 1119: LPTSTR TitleBuffer; ! 1120: LPTSTR *Title; ! 1121: DWORD Count; ! 1122: TCHAR szTemp[50]; ! 1123: DWORD dwR; ! 1124: ! 1125: ! 1126: dwR = GetPerfTitleSz (ghMachineKey, &TitleBuffer, &Title, &Count); ! 1127: ! 1128: if (dwR != ERROR_SUCCESS) ! 1129: { ! 1130: wsprintf (szTemp, TEXT("Unable to retrieve counter indexes, ERROR -> %#x"), dwR); ! 1131: MessageBox (hWnd, szTemp, TEXT("Pviewer"), MB_OK|MB_ICONEXCLAMATION); ! 1132: return; ! 1133: } ! 1134: ! 1135: ! 1136: PX_PROCESS = GetTitleIdx (hWnd, Title, Count, PN_PROCESS); ! 1137: PX_PROCESS_CPU = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_CPU); ! 1138: PX_PROCESS_PRIV = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIV); ! 1139: PX_PROCESS_USER = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_USER); ! 1140: PX_PROCESS_WORKING_SET = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_WORKING_SET); ! 1141: PX_PROCESS_PEAK_WS = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PEAK_WS); ! 1142: PX_PROCESS_PRIO = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIO); ! 1143: PX_PROCESS_ELAPSE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_ELAPSE); ! 1144: PX_PROCESS_ID = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_ID); ! 1145: PX_PROCESS_PRIVATE_PAGE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_PAGE); ! 1146: PX_PROCESS_VIRTUAL_SIZE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_VIRTUAL_SIZE); ! 1147: PX_PROCESS_PEAK_VS = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PEAK_VS); ! 1148: PX_PROCESS_FAULT_COUNT = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_FAULT_COUNT); ! 1149: ! 1150: PX_THREAD = GetTitleIdx (hWnd, Title, Count, PN_THREAD); ! 1151: PX_THREAD_CPU = GetTitleIdx (hWnd, Title, Count, PN_THREAD_CPU); ! 1152: PX_THREAD_PRIV = GetTitleIdx (hWnd, Title, Count, PN_THREAD_PRIV); ! 1153: PX_THREAD_USER = GetTitleIdx (hWnd, Title, Count, PN_THREAD_USER); ! 1154: PX_THREAD_START = GetTitleIdx (hWnd, Title, Count, PN_THREAD_START); ! 1155: PX_THREAD_SWITCHES = GetTitleIdx (hWnd, Title, Count, PN_THREAD_SWITCHES); ! 1156: PX_THREAD_PRIO = GetTitleIdx (hWnd, Title, Count, PN_THREAD_PRIO); ! 1157: PX_THREAD_BASE_PRIO = GetTitleIdx (hWnd, Title, Count, PN_THREAD_BASE_PRIO); ! 1158: PX_THREAD_ELAPSE = GetTitleIdx (hWnd, Title, Count, PN_THREAD_ELAPSE); ! 1159: ! 1160: PX_THREAD_DETAILS = GetTitleIdx (hWnd, Title, Count, PN_THREAD_DETAILS); ! 1161: PX_THREAD_PC = GetTitleIdx (hWnd, Title, Count, PN_THREAD_PC); ! 1162: ! 1163: PX_IMAGE = GetTitleIdx (hWnd, Title, Count, PN_IMAGE); ! 1164: PX_IMAGE_NOACCESS = GetTitleIdx (hWnd, Title, Count, PN_IMAGE_NOACCESS); ! 1165: PX_IMAGE_READONLY = GetTitleIdx (hWnd, Title, Count, PN_IMAGE_READONLY); ! 1166: PX_IMAGE_READWRITE = GetTitleIdx (hWnd, Title, Count, PN_IMAGE_READWRITE); ! 1167: PX_IMAGE_WRITECOPY = GetTitleIdx (hWnd, Title, Count, PN_IMAGE_WRITECOPY); ! 1168: PX_IMAGE_EXECUTABLE = GetTitleIdx (hWnd, Title, Count, PN_IMAGE_EXECUTABLE); ! 1169: PX_IMAGE_EXE_READONLY = GetTitleIdx (hWnd, Title, Count, PN_IMAGE_EXE_READONLY); ! 1170: PX_IMAGE_EXE_READWRITE = GetTitleIdx (hWnd, Title, Count, PN_IMAGE_EXE_READWRITE); ! 1171: PX_IMAGE_EXE_WRITECOPY = GetTitleIdx (hWnd, Title, Count, PN_IMAGE_EXE_WRITECOPY); ! 1172: ! 1173: PX_PROCESS_ADDRESS_SPACE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_ADDRESS_SPACE); ! 1174: PX_PROCESS_PRIVATE_NOACCESS = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_NOACCESS); ! 1175: PX_PROCESS_PRIVATE_READONLY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_READONLY); ! 1176: PX_PROCESS_PRIVATE_READWRITE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_READWRITE); ! 1177: PX_PROCESS_PRIVATE_WRITECOPY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_WRITECOPY); ! 1178: PX_PROCESS_PRIVATE_EXECUTABLE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_EXECUTABLE); ! 1179: PX_PROCESS_PRIVATE_EXE_READONLY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_EXE_READONLY); ! 1180: PX_PROCESS_PRIVATE_EXE_READWRITE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_EXE_READWRITE); ! 1181: PX_PROCESS_PRIVATE_EXE_WRITECOPY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_PRIVATE_EXE_WRITECOPY); ! 1182: ! 1183: PX_PROCESS_MAPPED_NOACCESS = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_MAPPED_NOACCESS); ! 1184: PX_PROCESS_MAPPED_READONLY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_MAPPED_READONLY); ! 1185: PX_PROCESS_MAPPED_READWRITE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_MAPPED_READWRITE); ! 1186: PX_PROCESS_MAPPED_WRITECOPY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_MAPPED_WRITECOPY); ! 1187: PX_PROCESS_MAPPED_EXECUTABLE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_MAPPED_EXECUTABLE); ! 1188: PX_PROCESS_MAPPED_EXE_READONLY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_MAPPED_EXE_READONLY); ! 1189: PX_PROCESS_MAPPED_EXE_READWRITE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_MAPPED_EXE_READWRITE); ! 1190: PX_PROCESS_MAPPED_EXE_WRITECOPY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_MAPPED_EXE_WRITECOPY); ! 1191: ! 1192: PX_PROCESS_IMAGE_NOACCESS = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_IMAGE_NOACCESS); ! 1193: PX_PROCESS_IMAGE_READONLY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_IMAGE_READONLY); ! 1194: PX_PROCESS_IMAGE_READWRITE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_IMAGE_READWRITE); ! 1195: PX_PROCESS_IMAGE_WRITECOPY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_IMAGE_WRITECOPY); ! 1196: PX_PROCESS_IMAGE_EXECUTABLE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_IMAGE_EXECUTABLE); ! 1197: PX_PROCESS_IMAGE_EXE_READONLY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_IMAGE_EXE_READONLY); ! 1198: PX_PROCESS_IMAGE_EXE_READWRITE = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_IMAGE_EXE_READWRITE); ! 1199: PX_PROCESS_IMAGE_EXE_WRITECOPY = GetTitleIdx (hWnd, Title, Count, PN_PROCESS_IMAGE_EXE_WRITECOPY); ! 1200: ! 1201: ! 1202: wsprintf (INDEX_PROCTHRD_OBJ, TEXT("%ld %ld"), PX_PROCESS, PX_THREAD); ! 1203: wsprintf (INDEX_COSTLY_OBJ, TEXT("%ld %ld %ld"), ! 1204: PX_PROCESS_ADDRESS_SPACE, PX_IMAGE, PX_THREAD_DETAILS); ! 1205: ! 1206: ! 1207: LocalFree (TitleBuffer); ! 1208: LocalFree (Title); ! 1209: ! 1210: } ! 1211: ! 1212: ! 1213: ! 1214: ! 1215: //******************************************************** ! 1216: // ! 1217: // GetTitleIdx ! 1218: // ! 1219: // Searches Titles[] for Name. Returns the index found. ! 1220: // ! 1221: DWORD GetTitleIdx (HWND hWnd, LPTSTR Title[], DWORD LastIndex, LPTSTR Name) ! 1222: { ! 1223: DWORD Index; ! 1224: ! 1225: for (Index = 0; Index <= LastIndex; Index++) ! 1226: if (Title[Index]) ! 1227: if (!lstrcmpi (Title[Index], Name)) ! 1228: return Index; ! 1229: ! 1230: MessageBox (hWnd, Name, TEXT("Pviewer cannot find index"), MB_OK); ! 1231: return 0; ! 1232: } ! 1233: ! 1234: ! 1235: ! 1236: ! 1237: //******************************************************** ! 1238: // ! 1239: // SetListBoxTabStops -- ! 1240: // ! 1241: // Set tab stops in the two list boxes. ! 1242: // ! 1243: void SetListBoxTabStops (HWND hWnd) ! 1244: { ! 1245: HWND hListBox; ! 1246: INT Tabs[4] = {22*4, 36*4, 44*4}; ! 1247: ! 1248: hListBox = GetDlgItem (hWnd, PVIEW_PROCESS_LIST); ! 1249: SendMessage (hListBox, LB_SETTABSTOPS, 3, (DWORD)Tabs); ! 1250: ! 1251: hListBox = GetDlgItem (hWnd, PVIEW_THREAD_LIST); ! 1252: SendMessage (hListBox, LB_SETTABSTOPS, 3, (DWORD)Tabs); ! 1253: } ! 1254: ! 1255: ! 1256: ! 1257: ! 1258: //******************************************************** ! 1259: // ! 1260: // SetLocalMachine -- ! 1261: // ! 1262: // Set local machine as performance data focus. ! 1263: // ! 1264: // Sets ghPerfKey ! 1265: // ghMachineKey ! 1266: // gszMachineName ! 1267: // gszCurrentMachine ! 1268: // ! 1269: void SetLocalMachine (void) ! 1270: { ! 1271: TCHAR szName[MACHINE_NAME_SIZE]; ! 1272: DWORD dwSize = MACHINE_NAME_SIZE; ! 1273: ! 1274: ! 1275: // performance_data key on local machine ! 1276: // ! 1277: ghPerfKey = HKEY_PERFORMANCE_DATA; ! 1278: ghMachineKey = HKEY_LOCAL_MACHINE; ! 1279: ! 1280: ! 1281: ! 1282: // get computer name ! 1283: GetComputerName (szName, &dwSize); ! 1284: ! 1285: ! 1286: ! 1287: if (szName[0] != '\\' || szName[1] != '\\') // must have two '\\' ! 1288: { ! 1289: wsprintf (gszMachineName, TEXT("\\\\%s"), szName); ! 1290: lstrcpy (gszCurrentMachine, gszMachineName); ! 1291: } ! 1292: else ! 1293: { ! 1294: lstrcpy (gszMachineName, szName); ! 1295: lstrcpy (gszCurrentMachine, gszMachineName); ! 1296: } ! 1297: ! 1298: } ! 1299: ! 1300: ! 1301: ! 1302: ! 1303: //******************************************************** ! 1304: // ! 1305: // ConnectComputer -- ! 1306: // ! 1307: // Connect to a computer with name entered in PVIEW_COMPUTER. ! 1308: // If a new connection is made, then return TRUE else return FALSE. ! 1309: // ! 1310: // Sets gszCurrentMachine ! 1311: // ghPerfKey ! 1312: // ghMachineKey ! 1313: // ! 1314: BOOL ConnectComputer (HWND hWnd) ! 1315: { ! 1316: DWORD dwR; ! 1317: HKEY hKey; ! 1318: TCHAR szTemp[MACHINE_NAME_SIZE]; ! 1319: TCHAR szTemp2[MACHINE_NAME_SIZE+100]; ! 1320: BOOL bResult = TRUE; ! 1321: ! 1322: ! 1323: ! 1324: SetCursor (ghCursor[1]); ! 1325: ! 1326: ! 1327: if (!GetDlgItemText (hWnd, PVIEW_COMPUTER, szTemp, sizeof (szTemp))) ! 1328: { ! 1329: SetLocalMachine (); ! 1330: SetDlgItemText (hWnd, PVIEW_COMPUTER, gszCurrentMachine); ! 1331: } ! 1332: ! 1333: else if (!lstrcmpi (szTemp, gszCurrentMachine)) // didn't change name ! 1334: bResult = FALSE; ! 1335: ! 1336: else if (!lstrcmpi (szTemp, gszMachineName)) // local machine ! 1337: { ! 1338: SetLocalMachine (); ! 1339: EnableControls (hWnd); ! 1340: } ! 1341: ! 1342: else ! 1343: { ! 1344: // a remote machine, connect to it ! 1345: // ! 1346: dwR = RegConnectRegistry (szTemp, HKEY_PERFORMANCE_DATA, &hKey); ! 1347: ! 1348: if (dwR != ERROR_SUCCESS) ! 1349: { ! 1350: wsprintf (szTemp2, TEXT("Cannot connect to computer %s"), szTemp); ! 1351: MessageBox (hWnd, szTemp2, TEXT(""), MB_ICONEXCLAMATION|MB_OK); ! 1352: ! 1353: SetDlgItemText (hWnd, PVIEW_COMPUTER, gszCurrentMachine); ! 1354: ! 1355: bResult = FALSE; ! 1356: } ! 1357: else ! 1358: { ! 1359: // connected ! 1360: // ! 1361: lstrcpy (gszCurrentMachine, szTemp); ! 1362: ghPerfKey = hKey; ! 1363: ! 1364: DisableControls (hWnd); ! 1365: ! 1366: ! 1367: // we also need to get the remote machine's title indexes. ! 1368: // ! 1369: dwR = RegConnectRegistry (gszCurrentMachine, HKEY_LOCAL_MACHINE, &hKey); ! 1370: ! 1371: if (dwR == ERROR_SUCCESS) ! 1372: ghMachineKey = hKey; ! 1373: else ! 1374: // unable to connect, so we'll use our own indexes. ! 1375: // ! 1376: ghMachineKey = HKEY_LOCAL_MACHINE; ! 1377: } ! 1378: } ! 1379: ! 1380: SetCursor (ghCursor[0]); ! 1381: ! 1382: ! 1383: EnableWindow (GetDlgItem (hWnd, PVIEW_CONNECT), FALSE); ! 1384: ! 1385: ! 1386: return bResult; ! 1387: ! 1388: } ! 1389: ! 1390: ! 1391: ! 1392: ! 1393: //******************************************************** ! 1394: // ! 1395: // DisableControls -- ! 1396: // ! 1397: // Disable controls that don't make sense on remote machine ! 1398: // ! 1399: void DisableControls (HWND hPviewDlg) ! 1400: { ! 1401: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_TERMINATE), FALSE); ! 1402: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_PRIORITY_HIGH), FALSE); ! 1403: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_PRIORITY_NORMAL), FALSE); ! 1404: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_PRIORITY_IDL), FALSE); ! 1405: } ! 1406: ! 1407: ! 1408: ! 1409: ! 1410: //******************************************************** ! 1411: // ! 1412: // EnableControls -- ! 1413: // ! 1414: // Enable controls disabled by DisableControl(). ! 1415: // ! 1416: void EnableControls (HWND hPviewDlg) ! 1417: { ! 1418: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_TERMINATE), TRUE); ! 1419: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_PRIORITY_HIGH), TRUE); ! 1420: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_PRIORITY_NORMAL), TRUE); ! 1421: EnableWindow (GetDlgItem (hPviewDlg, PVIEW_PRIORITY_IDL), TRUE); ! 1422: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.