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.

1211 lines
31 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Vdmperf.c
  5. Abstract:
  6. Win32 application to display VDM performance statictics.
  7. Author:
  8. Mark Lucovsky (stolen from Mark Enstrom (marke) winperf)
  9. Environment:
  10. Win32
  11. Revision History:
  12. 11-05-92 Initial version
  13. --*/
  14. //
  15. // set variable to define global variables
  16. //
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <errno.h>
  22. #include "vdmperf.h"
  23. //
  24. // global handles
  25. //
  26. HANDLE hInst;
  27. //
  28. // Selected Display Mode (read from wp2.ini), default set here.
  29. //
  30. DISPLAY_ITEM PerfDataList[SAVE_SUBJECTS];
  31. VDMPERF_INFO VdmperfInfo;
  32. //
  33. // Window names
  34. //
  35. PUCHAR PerfNames[] = {
  36. "PUSHF",
  37. "POPF",
  38. "IRET",
  39. "HLT",
  40. "CLI",
  41. "STI",
  42. "BOP",
  43. "SEG_NOT_P",
  44. "VDMOPCODEF",
  45. "INTNN",
  46. "INTO",
  47. "INB",
  48. "INW",
  49. "OUTB",
  50. "OUTW",
  51. "INSB",
  52. "INSW",
  53. "OUTSB",
  54. "OUTSW"
  55. };
  56. int
  57. __cdecl
  58. main(USHORT argc, CHAR **argv)
  59. /*++
  60. Routine Description:
  61. Windows entry point routine
  62. Arguments:
  63. Return Value:
  64. status of operation
  65. Revision History:
  66. 03-21-91 Initial code
  67. --*/
  68. {
  69. //
  70. //
  71. //
  72. HANDLE hInstance = MGetInstHandle();
  73. HANDLE hPrevInstance = (HANDLE)NULL;
  74. LPSTR lpCmdLine = MGetCmdLine();
  75. INT nCmdShow = SW_SHOWDEFAULT;
  76. USHORT _argc = argc;
  77. CHAR **_argv = argv;
  78. MSG msg;
  79. HBRUSH BackBrush;
  80. //
  81. // check for other instances of this program
  82. //
  83. BackBrush = CreateSolidBrush(RGB(192,192,192));
  84. if (!InitApplication(hInstance,BackBrush)) {
  85. DbgPrint("Init Application fails\n");
  86. return (FALSE);
  87. }
  88. //
  89. // Perform initializations that apply to a specific instance
  90. //
  91. if (!InitInstance(hInstance, nCmdShow)){
  92. DbgPrint("Init Instance failed\n");
  93. return (FALSE);
  94. }
  95. //
  96. // Acquire and dispatch messages until a WM_QUIT message is received.
  97. //
  98. while (GetMessage(&msg, // message structure
  99. (HWND)NULL, // handle of window receiving the message
  100. 0, // lowest message to examine
  101. 0)) // highest message to examine
  102. {
  103. TranslateMessage(&msg); // Translates virtual key codes
  104. DispatchMessage(&msg); // Dispatches message to window
  105. }
  106. DeleteObject(BackBrush);
  107. return ((INT)msg.wParam); // Returns the value from PostQuitMessage
  108. }
  109. BOOL
  110. InitApplication(
  111. HANDLE hInstance,
  112. HBRUSH hBackground)
  113. /*++
  114. Routine Description:
  115. Initializes window data and registers window class.
  116. Arguments:
  117. hInstance - current instance
  118. hBackground - background fill brush
  119. Return Value:
  120. status of operation
  121. Revision History:
  122. 02-17-91 Initial code
  123. --*/
  124. {
  125. WNDCLASS wc;
  126. BOOL ReturnStatus;
  127. //
  128. // Fill in window class structure with parameters that describe the
  129. // main window.
  130. //
  131. wc.style = CS_DBLCLKS; // Class style(s).
  132. wc.lpfnWndProc = MainWndProc; // Function to retrieve messages for
  133. // windows of this class.
  134. wc.cbClsExtra = 0; // No per-class extra data.
  135. wc.cbWndExtra = 0; // No per-window extra data.
  136. wc.hInstance = hInstance; // Application that owns the class.
  137. wc.hIcon = LoadIcon(hInstance, //
  138. MAKEINTRESOURCE(WINPERF_ICON)); // Load Winperf icon
  139. wc.hCursor = LoadCursor((HANDLE)NULL, IDC_ARROW); // Load default cursor
  140. wc.hbrBackground = hBackground;; // Use background passed to routine
  141. wc.lpszMenuName = "vdmperfMenu"; // Name of menu resource in .RC file.
  142. wc.lpszClassName = "VdmPerfClass"; // Name used in call to CreateWindow.
  143. ReturnStatus = RegisterClass(&wc);
  144. return(ReturnStatus);
  145. }
  146. BOOL
  147. InitInstance(
  148. HANDLE hInstance,
  149. int nCmdShow
  150. )
  151. /*++
  152. Routine Description:
  153. Save instance handle and create main window. This function performs
  154. initialization tasks that cannot be shared by multiple instances.
  155. Arguments:
  156. hInstance - Current instance identifier.
  157. nCmdShow - Param for first ShowWindow() call.
  158. Return Value:
  159. status of operation
  160. Revision History:
  161. 02-17-91 Initial code
  162. --*/
  163. {
  164. DWORD WindowStyle;
  165. //
  166. // Save the instance handle in a static variable, which will be used in
  167. // many subsequent calls from this application to Windows.
  168. //
  169. hInst = hInstance;
  170. //
  171. // init the window position and size to be in the upper corner of
  172. // the screen, 200x100
  173. //
  174. //
  175. // What I want here is a way to get the WINDOW dimensions
  176. //
  177. VdmperfInfo.WindowPositionX = 640 - 200;
  178. VdmperfInfo.WindowPositionY = 0;
  179. VdmperfInfo.WindowSizeX = 200;
  180. VdmperfInfo.WindowSizeY = 100;
  181. //
  182. // read profile data from .ini file
  183. //
  184. InitProfileData(&VdmperfInfo);
  185. VdmperfInfo.hMenu = LoadMenu(hInstance,"vdmperfMenu");
  186. //
  187. // Create a main window for this application instance.
  188. //
  189. VdmperfInfo.hWndMain = CreateWindow(
  190. "VdmPerfClass", // See RegisterClass() call.
  191. "VDM Perf", // Text for window title bar.
  192. WS_OVERLAPPEDWINDOW, // window style
  193. VdmperfInfo.WindowPositionX, // Default horizontal position.
  194. VdmperfInfo.WindowPositionY, // Default vertical position.
  195. VdmperfInfo.WindowSizeX, // Default width.
  196. VdmperfInfo.WindowSizeY, // Default height.
  197. (HWND)NULL, // Overlapped windows have no parent.
  198. (HMENU)NULL, // Use the window class menu.
  199. hInstance, // This instance owns this window.
  200. (LPVOID)NULL // Pointer not needed.
  201. );
  202. //
  203. // Decide on whether or not to display the menu and caption
  204. // based on the window class read from the .ini file
  205. //
  206. if (VdmperfInfo.DisplayMode==STYLE_ENABLE_MENU) {
  207. VdmperfInfo.DisplayMenu = TRUE;
  208. } else {
  209. VdmperfInfo.DisplayMenu = FALSE;
  210. WindowStyle = GetWindowLong(VdmperfInfo.hWndMain,GWL_STYLE);
  211. WindowStyle = (WindowStyle & (~STYLE_ENABLE_MENU)) | STYLE_DISABLE_MENU;
  212. SetWindowPos(VdmperfInfo.hWndMain, (HWND)NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME);
  213. SetWindowLong(VdmperfInfo.hWndMain,GWL_STYLE,WindowStyle);
  214. SetMenu(VdmperfInfo.hWndMain,NULL);
  215. }
  216. //
  217. // If window could not be created, return "failure"
  218. //
  219. if (!VdmperfInfo.hWndMain) {
  220. return (FALSE);
  221. }
  222. //
  223. // Make the window visible; update its client area; and return "success"
  224. //
  225. SetFocus(VdmperfInfo.hWndMain);
  226. ShowWindow(VdmperfInfo.hWndMain, SW_SHOWNORMAL);
  227. UpdateWindow(VdmperfInfo.hWndMain);
  228. return (TRUE);
  229. }
  230. LRESULT
  231. APIENTRY
  232. MainWndProc(
  233. HWND hWnd,
  234. UINT message,
  235. WPARAM wParam,
  236. LPARAM lParam
  237. )
  238. /*++
  239. Routine Description:
  240. Process messages.
  241. Arguments:
  242. hWnd - window hande
  243. message - type of message
  244. wParam - additional information
  245. lParam - additional information
  246. Return Value:
  247. status of operation
  248. Revision History:
  249. 02-17-91 Initial code
  250. --*/
  251. {
  252. PAINTSTRUCT ps;
  253. //
  254. // process each message
  255. //
  256. switch (message) {
  257. //
  258. // create window
  259. //
  260. case WM_CREATE:
  261. {
  262. HDC hDC = GetDC(hWnd);
  263. BOOLEAN Fit;
  264. UINT Index;
  265. //
  266. // make brushes and pens
  267. //
  268. VdmperfInfo.hBluePen = CreatePen(PS_SOLID,1,RGB(0,0,128));
  269. VdmperfInfo.hRedPen = CreatePen(PS_SOLID,1,RGB(255,0,0));
  270. VdmperfInfo.hGreenPen = CreatePen(PS_SOLID,1,RGB(0,255,0));
  271. VdmperfInfo.hDotPen = CreatePen(PS_DOT,1,RGB(0,0,0));
  272. VdmperfInfo.hBackground = CreateSolidBrush(RGB(192,192,192));
  273. VdmperfInfo.hLightBrush = CreateSolidBrush(RGB(255,255,255));
  274. VdmperfInfo.hDarkBrush = CreateSolidBrush(RGB(128,128,128));
  275. VdmperfInfo.hRedBrush = CreateSolidBrush(RGB(255,000,000));
  276. VdmperfInfo.hGreenBrush = CreateSolidBrush(RGB(000,255,000));
  277. VdmperfInfo.hBlueBrush = CreateSolidBrush(RGB(000,000,255));
  278. //
  279. // create thee fonts using NT default font families
  280. //
  281. VdmperfInfo.SmallFont = CreateFont(8,
  282. 0,
  283. 0,
  284. 0,
  285. 400,
  286. FALSE,
  287. FALSE,
  288. FALSE,
  289. ANSI_CHARSET,
  290. OUT_DEFAULT_PRECIS,
  291. CLIP_DEFAULT_PRECIS,
  292. DRAFT_QUALITY,
  293. DEFAULT_PITCH,
  294. "Small Fonts");
  295. VdmperfInfo.MediumFont = CreateFont(10,
  296. 0,
  297. 0,
  298. 0,
  299. 400,
  300. FALSE,
  301. FALSE,
  302. FALSE,
  303. ANSI_CHARSET,
  304. OUT_DEFAULT_PRECIS,
  305. CLIP_DEFAULT_PRECIS,
  306. DRAFT_QUALITY,
  307. DEFAULT_PITCH,
  308. "Times New Roman");
  309. VdmperfInfo.LargeFont = CreateFont(14,
  310. 0,
  311. 0,
  312. 0,
  313. 400,
  314. FALSE,
  315. FALSE,
  316. FALSE,
  317. ANSI_CHARSET,
  318. OUT_DEFAULT_PRECIS,
  319. CLIP_DEFAULT_PRECIS,
  320. DRAFT_QUALITY,
  321. DEFAULT_PITCH,
  322. "Times New Roman");
  323. //
  324. // create a system timer event to call performance gathering routines by.
  325. //
  326. VdmperfInfo.TimerId = SetTimer(hWnd,(UINT)TIMER_ID,(UINT)1000 * DELAY_SECONDS,(TIMERPROC)NULL);
  327. //
  328. // init display variables
  329. //
  330. InitPerfWindowDisplay(hWnd,hDC,PerfDataList,SAVE_SUBJECTS);
  331. //
  332. // Fit the perf windows into the main window
  333. //
  334. Fit = FitPerfWindows(hWnd,hDC,PerfDataList,SAVE_SUBJECTS);
  335. if (!Fit) {
  336. DbgPrint("FitPerfWindows Fails !\n");
  337. }
  338. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  339. CalcDrawFrame(&PerfDataList[Index]);
  340. if (!CreateMemoryContext(hDC,&PerfDataList[Index])) {
  341. MessageBox(hWnd,"Error Allocating Memory","Vdmperf",MB_OK);
  342. DestroyWindow(hWnd);
  343. break;
  344. }
  345. }
  346. //
  347. // init performance routines
  348. //
  349. InitPerfInfo();
  350. //
  351. // release the DC handle
  352. //
  353. ReleaseDC(hWnd,hDC);
  354. }
  355. break;
  356. //
  357. // re-size
  358. //
  359. case WM_SIZE:
  360. {
  361. int i;
  362. HDC hDC = GetDC(hWnd);
  363. RECT ClientRect;
  364. BOOLEAN Fit;
  365. //
  366. // get size of cleint area
  367. //
  368. GetWindowRect(hWnd,&ClientRect);
  369. VdmperfInfo.WindowPositionX = ClientRect.left;
  370. VdmperfInfo.WindowPositionY = ClientRect.top;
  371. VdmperfInfo.WindowSizeX = ClientRect.right - ClientRect.left;
  372. VdmperfInfo.WindowSizeY = ClientRect.bottom - ClientRect.top;
  373. Fit = FitPerfWindows(hWnd,hDC,PerfDataList,SAVE_SUBJECTS);
  374. if (!Fit) {
  375. DbgPrint("WM_SIZE error, FitPerf returns FALSE\n");
  376. }
  377. for (i=0;i<SAVE_SUBJECTS;i++) {
  378. DeleteMemoryContext(&PerfDataList[i]);
  379. CalcDrawFrame(&PerfDataList[i]);
  380. if (!CreateMemoryContext(hDC,&PerfDataList[i])) {
  381. MessageBox(hWnd,"Error Allocating Memory","Vdmperf",MB_OK);
  382. DestroyWindow(hWnd);
  383. break;
  384. }
  385. }
  386. //
  387. // force window to be re-painted
  388. //
  389. InvalidateRect(hWnd,(LPRECT)NULL,TRUE);
  390. //
  391. // release the DC handle
  392. //
  393. ReleaseDC(hWnd,hDC);
  394. }
  395. break;
  396. case WM_MOVE:
  397. {
  398. HDC hDC = GetDC(hWnd);
  399. RECT ClientRect;
  400. //
  401. // get size of cleint area
  402. //
  403. GetWindowRect(hWnd,&ClientRect);
  404. VdmperfInfo.WindowPositionX = ClientRect.left;
  405. VdmperfInfo.WindowPositionY = ClientRect.top;
  406. VdmperfInfo.WindowSizeX = ClientRect.right - ClientRect.left;
  407. VdmperfInfo.WindowSizeY = ClientRect.bottom - ClientRect.top;
  408. ReleaseDC(hWnd,hDC);
  409. }
  410. break;
  411. //
  412. // command from application menu
  413. //
  414. case WM_COMMAND:
  415. switch (wParam){
  416. //
  417. // exit window
  418. //
  419. case IDM_EXIT:
  420. DestroyWindow(hWnd);
  421. break;
  422. //
  423. // about command
  424. //
  425. case IDM_SELECT:
  426. {
  427. HDC hDC = GetDC(hWnd);
  428. int Index;
  429. BOOLEAN fit;
  430. if (DialogBox(hInst,MAKEINTRESOURCE(IDM_SEL_DLG),hWnd,SelectDlgProc) == DIALOG_SUCCESS) {
  431. fit = FitPerfWindows(hWnd,hDC,PerfDataList,SAVE_SUBJECTS);
  432. if (!fit) {
  433. DbgPrint("Fit Fails\n");
  434. }
  435. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  436. DeleteMemoryContext(&PerfDataList[Index]);
  437. CalcDrawFrame(&PerfDataList[Index]);
  438. if (!CreateMemoryContext(hDC,&PerfDataList[Index])) {
  439. MessageBox(hWnd,"Error Allocating Memory","Vdmperf",MB_OK);
  440. DestroyWindow(hWnd);
  441. break;
  442. }
  443. }
  444. InvalidateRect(hWnd,(LPRECT)NULL,TRUE);
  445. }
  446. ReleaseDC(hWnd,hDC);
  447. }
  448. break;
  449. default:
  450. return (DefWindowProc(hWnd, message, wParam, lParam));
  451. }
  452. break;
  453. case WM_PAINT:
  454. //
  455. // repaint the window
  456. //
  457. {
  458. int i;
  459. HDC hDC = BeginPaint(hWnd,&ps);
  460. SelectObject(hDC,GetStockObject(NULL_BRUSH));
  461. for (i=0;i<SAVE_SUBJECTS;i++) {
  462. if (PerfDataList[i].Display == TRUE) {
  463. DrawFrame(hDC,&PerfDataList[i]);
  464. DrawPerfText(hDC,&PerfDataList[i],i);
  465. DrawPerfGraph(hDC,&PerfDataList[i]);
  466. }
  467. }
  468. EndPaint(hWnd,&ps);
  469. }
  470. break;
  471. case WM_TIMER:
  472. {
  473. int i;
  474. HDC hDC = GetDC(hWnd);
  475. CalcCpuTime(PerfDataList);
  476. //
  477. // update all performance information
  478. //
  479. for (i=0;i<SAVE_SUBJECTS;i++) {
  480. if (PerfDataList[i].Display == TRUE) {
  481. DrawPerfText(hDC,&PerfDataList[i],i);
  482. if (PerfDataList[i].ChangeScale) {
  483. DrawPerfGraph(hDC,&PerfDataList[i]);
  484. } else {
  485. ShiftPerfGraph(hDC,&PerfDataList[i]);
  486. }
  487. }
  488. }
  489. ReleaseDC(hWnd,hDC);
  490. }
  491. break;
  492. //
  493. // handle a double click
  494. //
  495. case WM_NCLBUTTONDBLCLK:
  496. case WM_LBUTTONDBLCLK:
  497. {
  498. DWORD WindowStyle;
  499. //
  500. // get old window style, take out caption and menu
  501. //
  502. if (!IsIconic(hWnd)) {
  503. if (VdmperfInfo.DisplayMenu) {
  504. WindowStyle = GetWindowLong(hWnd,GWL_STYLE);
  505. WindowStyle = (WindowStyle & (~STYLE_ENABLE_MENU)) | STYLE_DISABLE_MENU;
  506. SetMenu(hWnd,NULL);
  507. SetWindowLong(hWnd,GWL_STYLE,WindowStyle);
  508. SetWindowPos(hWnd, (HWND)NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME);
  509. ShowWindow(hWnd,SW_SHOW);
  510. VdmperfInfo.DisplayMode=STYLE_DISABLE_MENU;
  511. VdmperfInfo.DisplayMenu = FALSE;
  512. } else {
  513. WindowStyle = GetWindowLong(hWnd,GWL_STYLE);
  514. WindowStyle = (WindowStyle & (~STYLE_DISABLE_MENU)) | STYLE_ENABLE_MENU;
  515. SetMenu(hWnd,VdmperfInfo.hMenu);
  516. SetWindowLong(hWnd,GWL_STYLE,WindowStyle);
  517. SetWindowPos(hWnd, (HWND)NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_DRAWFRAME);
  518. ShowWindow(hWnd,SW_SHOW);
  519. VdmperfInfo.DisplayMode=STYLE_ENABLE_MENU;
  520. VdmperfInfo.DisplayMenu = TRUE;
  521. }
  522. } else {
  523. DefWindowProc(hWnd, message, wParam, lParam);
  524. }
  525. }
  526. break;
  527. //
  528. // enable dragging with mouse in non-client
  529. //
  530. case WM_NCHITTEST:
  531. {
  532. lParam = DefWindowProc(hWnd, message, wParam, lParam);
  533. if ((VdmperfInfo.DisplayMenu==FALSE) && (lParam == HTCLIENT)) {
  534. return(HTCAPTION);
  535. } else {
  536. return(lParam);
  537. }
  538. }
  539. break;
  540. case WM_DESTROY:
  541. {
  542. UINT Index;
  543. //
  544. // Save profile info
  545. //
  546. SaveProfileData(&VdmperfInfo);
  547. //
  548. // Delete Windows Objects
  549. //
  550. KillTimer(hWnd,TIMER_ID);
  551. DeleteObject(VdmperfInfo.hBluePen);
  552. DeleteObject(VdmperfInfo.hRedPen);
  553. DeleteObject(VdmperfInfo.hGreenPen);
  554. DeleteObject(VdmperfInfo.hBackground);
  555. DeleteObject(VdmperfInfo.hLightBrush);
  556. DeleteObject(VdmperfInfo.hDarkBrush);
  557. for (Index=0;Index<SAVE_SUBJECTS;Index++ ) {
  558. DeleteMemoryContext(&PerfDataList[Index]);
  559. }
  560. //
  561. // Destroy window
  562. //
  563. PostQuitMessage(0);
  564. }
  565. break;
  566. default:
  567. //
  568. // Passes message on if unproccessed
  569. //
  570. return (DefWindowProc(hWnd, message, wParam, lParam));
  571. }
  572. return (0);
  573. }
  574. INT_PTR
  575. APIENTRY SelectDlgProc(
  576. HWND hDlg,
  577. unsigned message,
  578. WPARAM wParam,
  579. LPARAM lParam
  580. )
  581. /*++
  582. Routine Description:
  583. Process message for select dialog box.
  584. Arguments:
  585. hDlg - window handle of the dialog box
  586. message - type of message
  587. wParam - message-specific information
  588. lParam - message-specific information
  589. Return Value:
  590. status of operation
  591. Revision History:
  592. 03-21-91 Initial code
  593. --*/
  594. {
  595. UINT ButtonState;
  596. UINT Index;
  597. switch (message) {
  598. case WM_INITDIALOG:
  599. //
  600. // Init Buttons with PerfDataList Structure
  601. //
  602. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  603. int Idm;
  604. switch ( Index ) {
  605. case IX_PUSHF : Idm = IDM_PUSHF ; break;
  606. case IX_POPF : Idm = IDM_POPF ; break;
  607. case IX_IRET : Idm = IDM_IRET ; break;
  608. case IX_HLT : Idm = IDM_HLT ; break;
  609. case IX_CLI : Idm = IDM_CLI ; break;
  610. case IX_STI : Idm = IDM_STI ; break;
  611. case IX_BOP : Idm = IDM_BOP ; break;
  612. case IX_SEGNOTP : Idm = IDM_SEGNOTP ; break;
  613. case IX_VDMOPCODEF : Idm = IDM_VDMOPCODEF; break;
  614. case IX_INTNN : Idm = IDM_INTNN ; break;
  615. case IX_INTO : Idm = IDM_INTO ; break;
  616. case IX_INB : Idm = IDM_INB ; break;
  617. case IX_INW : Idm = IDM_INW ; break;
  618. case IX_OUTB : Idm = IDM_OUTB ; break;
  619. case IX_OUTW : Idm = IDM_OUTW ; break;
  620. case IX_INSB : Idm = IDM_INSB ; break;
  621. case IX_INSW : Idm = IDM_INSW ; break;
  622. case IX_OUTSB : Idm = IDM_OUTSB ; break;
  623. case IX_OUTSW : Idm = IDM_OUTSW ; break;
  624. }
  625. //
  626. // Set or clear radio button based on display variable
  627. //
  628. if (PerfDataList[Index].Display == TRUE) {
  629. CheckDlgButton(hDlg,Idm,1);
  630. } else {
  631. CheckDlgButton(hDlg,Idm,0);
  632. }
  633. }
  634. return (TRUE);
  635. case WM_COMMAND:
  636. switch(wParam) {
  637. //
  638. // end function
  639. //
  640. case IDOK:
  641. //DbgPrint("IDOK: Check button states\n");
  642. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  643. int Idm;
  644. switch ( Index ) {
  645. case IX_PUSHF : Idm = IDM_PUSHF ; break;
  646. case IX_POPF : Idm = IDM_POPF ; break;
  647. case IX_IRET : Idm = IDM_IRET ; break;
  648. case IX_HLT : Idm = IDM_HLT ; break;
  649. case IX_CLI : Idm = IDM_CLI ; break;
  650. case IX_STI : Idm = IDM_STI ; break;
  651. case IX_BOP : Idm = IDM_BOP ; break;
  652. case IX_SEGNOTP : Idm = IDM_SEGNOTP ; break;
  653. case IX_VDMOPCODEF : Idm = IDM_VDMOPCODEF; break;
  654. case IX_INTNN : Idm = IDM_INTNN ; break;
  655. case IX_INTO : Idm = IDM_INTO ; break;
  656. case IX_INB : Idm = IDM_INB ; break;
  657. case IX_INW : Idm = IDM_INW ; break;
  658. case IX_OUTB : Idm = IDM_OUTB ; break;
  659. case IX_OUTW : Idm = IDM_OUTW ; break;
  660. case IX_INSB : Idm = IDM_INSB ; break;
  661. case IX_INSW : Idm = IDM_INSW ; break;
  662. case IX_OUTSB : Idm = IDM_OUTSB ; break;
  663. case IX_OUTSW : Idm = IDM_OUTSW ; break;
  664. }
  665. ButtonState = IsDlgButtonChecked(hDlg,Idm);
  666. if (ButtonState == 1) {
  667. PerfDataList[Index].Display = TRUE;
  668. VdmperfInfo.DisplayElement[Index] = 1;
  669. } else {
  670. PerfDataList[Index].Display = FALSE;
  671. VdmperfInfo.DisplayElement[Index] = 0;
  672. }
  673. }
  674. EndDialog(hDlg, DIALOG_SUCCESS);
  675. return (TRUE);
  676. case IDCANCEL:
  677. EndDialog(hDlg, DIALOG_CANCEL );
  678. return (TRUE);
  679. case IDM_PUSHF :
  680. case IDM_POPF :
  681. case IDM_IRET :
  682. case IDM_HLT :
  683. case IDM_CLI :
  684. case IDM_STI :
  685. case IDM_SEGNOTP :
  686. case IDM_BOP :
  687. case IDM_VDMOPCODEF:
  688. case IDM_INTNN :
  689. case IDM_INTO :
  690. case IDM_INB :
  691. case IDM_INW :
  692. case IDM_OUTB :
  693. case IDM_OUTW :
  694. case IDM_INSB :
  695. case IDM_INSW :
  696. case IDM_OUTSB :
  697. case IDM_OUTSW :
  698. //
  699. // Turn on or off button
  700. //
  701. ButtonState = IsDlgButtonChecked(hDlg,(UINT)wParam);
  702. //DbgPrint("ButtonState = %i\n",ButtonState);
  703. if (ButtonState == 0) {
  704. //
  705. // Set Button
  706. //
  707. ButtonState = 1;
  708. } else if (ButtonState == 1) {
  709. //
  710. // Clear Button
  711. //
  712. ButtonState = 0;
  713. } else {
  714. ButtonState = 0;
  715. }
  716. CheckDlgButton(hDlg,(UINT)wParam,ButtonState);
  717. return(TRUE);
  718. }
  719. }
  720. return (FALSE);
  721. }
  722. VOID
  723. InitProfileData(PVDMPERF_INFO pVdmperfInfo)
  724. /*++
  725. Routine Description:
  726. Attempt tp read the following fields from the vdmperf.ini file
  727. Arguments:
  728. WindowPositionX - Window initial x position
  729. WindowPositionY - Window initial y position
  730. WindowSizeX - Window initial width
  731. WindowSizey - Window Initial height
  732. DisplayMode - Window initial display mode
  733. Return Value:
  734. None, values are set to default before a call to this operation. If there is a problem then
  735. default:values are left unchanged.
  736. Revision History:
  737. 02-17-91 Initial code
  738. --*/
  739. {
  740. DWORD PositionX,PositionY,SizeX,SizeY,Mode,Index,Element[SAVE_SUBJECTS];
  741. UCHAR TempStr[256];
  742. PositionX = GetPrivateProfileInt("vdmperf","PositionX" ,pVdmperfInfo->WindowPositionX,"vdmperf.ini");
  743. PositionY = GetPrivateProfileInt("vdmperf","PositionY" ,pVdmperfInfo->WindowPositionY,"vdmperf.ini");
  744. SizeX = GetPrivateProfileInt("vdmperf","SizeX" ,pVdmperfInfo->WindowSizeX ,"vdmperf.ini");
  745. SizeY = GetPrivateProfileInt("vdmperf","SizeY" ,pVdmperfInfo->WindowSizeY ,"vdmperf.ini");
  746. //
  747. // read the first deiplay element with default 1
  748. //
  749. Element[0] = GetPrivateProfileInt("vdmperf","DisplayElement0",1,"vdmperf.ini");
  750. //
  751. // read the rest of the display elements with default 0
  752. //
  753. for (Index=1;Index<SAVE_SUBJECTS;Index++) {
  754. wsprintf(TempStr,"DisplayElement%i",Index);
  755. Element[Index] = GetPrivateProfileInt("vdmperf",TempStr,0,"vdmperf.ini");
  756. }
  757. Mode = GetPrivateProfileInt("vdmperf","DisplayMode",pVdmperfInfo->DisplayMode ,"vdmperf.ini");
  758. pVdmperfInfo->WindowPositionX = PositionX;
  759. pVdmperfInfo->WindowPositionY = PositionY;
  760. pVdmperfInfo->WindowSizeX = SizeX;
  761. pVdmperfInfo->WindowSizeY = SizeY;
  762. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  763. pVdmperfInfo->DisplayElement[Index] = Element[Index];
  764. }
  765. pVdmperfInfo->DisplayMode = Mode;
  766. }
  767. VOID
  768. SaveProfileData(PVDMPERF_INFO pVdmperfInfo)
  769. /*++
  770. Routine Description:
  771. Save profile data
  772. Arguments:
  773. WindowPositionX - Window initial x position
  774. WindowPositionY - Window initial y position
  775. WindowSizeX - Window initial width
  776. WindowSizey - Window Initial height
  777. DisplayMode - Window initial display mode
  778. Return Value:
  779. None.
  780. Revision History:
  781. 02-17-91 Initial code
  782. --*/
  783. {
  784. UCHAR TempStr[50],TempName[50];
  785. UINT Index;
  786. wsprintf(TempStr,"%i",pVdmperfInfo->WindowPositionX);
  787. WritePrivateProfileString("vdmperf","PositionX",TempStr,"vdmperf.ini");
  788. wsprintf(TempStr,"%i",pVdmperfInfo->WindowPositionY);
  789. WritePrivateProfileString("vdmperf","PositionY",TempStr,"vdmperf.ini");
  790. wsprintf(TempStr,"%i",pVdmperfInfo->WindowSizeX);
  791. WritePrivateProfileString("vdmperf","SizeX",TempStr,"vdmperf.ini");
  792. wsprintf(TempStr,"%i",pVdmperfInfo->WindowSizeY);
  793. WritePrivateProfileString("vdmperf","SizeY",TempStr,"vdmperf.ini");
  794. for (Index=0;Index<SAVE_SUBJECTS;Index++) {
  795. wsprintf(TempStr,"%li",pVdmperfInfo->DisplayElement[Index]);
  796. wsprintf(TempName,"DisplayElement%li",Index);
  797. WritePrivateProfileString("vdmperf",TempName,TempStr,"vdmperf.ini");
  798. }
  799. wsprintf(TempStr,"%li",pVdmperfInfo->DisplayMode);
  800. WritePrivateProfileString("vdmperf","DisplayMode",TempStr,"vdmperf.ini");
  801. }
  802. BOOLEAN
  803. InitPerfWindowDisplay(
  804. IN HWND hWnd,
  805. IN HDC hDC,
  806. IN PDISPLAY_ITEM DisplayItems,
  807. IN ULONG NumberOfWindows
  808. )
  809. /*++
  810. Routine Description:
  811. Init All perf windows to active, init data
  812. Arguments:
  813. hDC - Screen context
  814. DisplayItems - List of display structures
  815. NumberOfWindows - Number of sub-windows
  816. Return Value:
  817. Status
  818. Revision History:
  819. 02-17-91 Initial code
  820. --*/
  821. {
  822. int Index1;
  823. UINT Index;
  824. for (Index=0;Index<NumberOfWindows;Index++) {
  825. if (VdmperfInfo.DisplayElement[Index] == 0) {
  826. DisplayItems[Index].Display = FALSE;
  827. } else {
  828. DisplayItems[Index].Display = TRUE;
  829. }
  830. DisplayItems[Index].CurrentDrawingPos = 0;
  831. DisplayItems[Index].NumberOfElements = 1;
  832. for (Index1=0;Index1<DATA_LIST_LENGTH;Index1++) {
  833. DisplayItems[Index].KernelTime[Index1] = 0;
  834. DisplayItems[Index].UserTime[Index1] = 0;
  835. DisplayItems[Index].TotalTime[Index1] = 0;
  836. }
  837. }
  838. return(TRUE);
  839. }