|
|
1.1 ! root 1: ! 2: //==========================================================================// ! 3: // Includes // ! 4: //==========================================================================// ! 5: ! 6: ! 7: #include "perfmon.h" // basic defns, windows.h ! 8: #include "logoptns.h" // external declarations for this file ! 9: ! 10: #include "dlgs.h" // common dialog control IDs ! 11: #include "log.h" // for StartLog, SetLogTimer, CloseLog ! 12: #include "fileutil.h" // file utilities ! 13: #include "utils.h" // various utilities ! 14: #include "playback.h" // for PlayingBackLog ! 15: #include "pmhelpid.h" // Help IDs ! 16: ! 17: ! 18: ! 19: //==========================================================================// ! 20: // Local Data // ! 21: //==========================================================================// ! 22: ! 23: ! 24: DWORD iIntervalMSecs ; ! 25: BOOL bNeedToRelogData ; ! 26: BOOL bNeedToStartLog ; ! 27: BOOL bNeedToSetTimer ; ! 28: ! 29: static BOOL LocalManualRefresh ; ! 30: static BOOL bStopButtonClicked ; ! 31: extern HWND hWndLogEntries ; ! 32: ! 33: // This is a counter that is init. to 0. It is incremened by 1 ! 34: // when the user clikc the cancel button. ! 35: // It is set to -1 when we sent the cancell msg internally. ! 36: int bCancelled ; ! 37: TCHAR szmsgFILEOK[] = FILEOKSTRING ; ! 38: DWORD msgFILEOK ; ! 39: ! 40: //==========================================================================// ! 41: // Macros // ! 42: //==========================================================================// ! 43: ! 44: ! 45: #define LogOptionsOFNStyle \ ! 46: (OFN_ENABLETEMPLATE | OFN_HIDEREADONLY | \ ! 47: OFN_SHOWHELP | OFN_ENABLEHOOK) ! 48: ! 49: ! 50: ! 51: //==========================================================================// ! 52: // Local Functions // ! 53: //==========================================================================// ! 54: ! 55: void EnableFileControls (HDLG hDlg, BOOL bEnable) ! 56: { ! 57: DialogEnable (hDlg, stc3, bEnable) ; ! 58: DialogEnable (hDlg, lst1, bEnable) ; ! 59: DialogEnable (hDlg, stc1, bEnable) ; ! 60: DialogEnable (hDlg, lst2, bEnable) ; ! 61: DialogEnable (hDlg, stc2, bEnable) ; ! 62: DialogEnable (hDlg, cmb1, bEnable) ; ! 63: DialogEnable (hDlg, stc4, bEnable) ; ! 64: DialogEnable (hDlg, cmb2, bEnable) ; ! 65: DialogEnable (hDlg, edt1, bEnable) ; ! 66: } ! 67: ! 68: ! 69: //==========================================================================// ! 70: // Message Handlers // ! 71: //==========================================================================// ! 72: ! 73: ! 74: void static OnInitDialog (HDLG hDlg) ! 75: { ! 76: PLOG pLog ; ! 77: int i ; ! 78: BOOL DisplayManualRefresh ; ! 79: pLog = LogData (hWndLog) ; ! 80: ! 81: if (msgFILEOK == 0) ! 82: { ! 83: msgFILEOK = RegisterWindowMessage(szmsgFILEOK); ! 84: } ! 85: ! 86: bCancelled = 0 ; ! 87: ! 88: switch (pLog->iStatus) ! 89: { // switch ! 90: case iPMStatusClosed: ! 91: // DialogEnable (hDlg, IDD_LOGOPTPAUSE, FALSE) ; ! 92: break ; ! 93: ! 94: case iPMStatusPaused: ! 95: EnableFileControls (hDlg, FALSE) ; ! 96: DialogSetText (hDlg, IDD_LOGOPTSTART, IDS_STOP) ; ! 97: // DialogSetText (hDlg, IDD_LOGOPTPAUSE, IDS_RESUME) ; ! 98: break ; ! 99: ! 100: case iPMStatusCollecting: ! 101: EnableFileControls (hDlg, FALSE) ; ! 102: DialogSetText (hDlg, IDD_LOGOPTSTART, IDS_STOP) ; ! 103: break ; ! 104: } // switch ! 105: ! 106: for (i = 0 ; ! 107: i < NumIntervals ; ! 108: i++) ! 109: CBAddInt (DialogControl (hDlg, IDD_LOGOPTINTERVAL), aiIntervals [i]) ; ! 110: DialogSetInterval (hDlg, IDD_LOGOPTINTERVAL, pLog->iIntervalMSecs) ; ! 111: iIntervalMSecs = pLog->iIntervalMSecs ; ! 112: ! 113: LocalManualRefresh = pLog->bManualRefresh ; ! 114: DisplayManualRefresh = TRUE ; ! 115: ! 116: if (PlayingBackLog ()) ! 117: { ! 118: DialogSetText (hDlg, IDD_LOGOPTSTART, IDS_CREATELOGFILE) ; ! 119: DisplayManualRefresh = FALSE ; ! 120: } ! 121: ! 122: if (LBNumItems (hWndLogEntries) == 0) ! 123: { ! 124: DialogEnable (hDlg, IDD_LOGOPTSTART, FALSE) ; ! 125: // DialogEnable (hDlg, IDD_LOGOPTPAUSE, FALSE) ; ! 126: } ! 127: ! 128: if (DisplayManualRefresh) ! 129: { ! 130: if (LocalManualRefresh) ! 131: { ! 132: DialogEnable (hDlg, IDD_LOGOPTINTERVAL, FALSE) ; ! 133: DialogEnable (hDlg, IDD_LOGOPTINTERVALTEXT, FALSE) ; ! 134: } ! 135: ! 136: CheckRadioButton (hDlg, ! 137: IDD_LOGOPTIONSMANUALREFRESH, ! 138: IDD_LOGOPTIONSPERIODIC, ! 139: LocalManualRefresh ? IDD_LOGOPTIONSMANUALREFRESH : ! 140: IDD_LOGOPTIONSPERIODIC) ; ! 141: } ! 142: else ! 143: { ! 144: DialogEnable (hDlg, IDD_LOGOPTIONSMANUALREFRESH, FALSE) ; ! 145: CheckRadioButton (hDlg, ! 146: IDD_LOGOPTIONSMANUALREFRESH, ! 147: IDD_LOGOPTIONSPERIODIC, ! 148: IDD_LOGOPTIONSPERIODIC) ; ! 149: } ! 150: ! 151: ! 152: dwCurrentDlgID = HC_PM_idDlgOptionLog ; ! 153: ! 154: WindowCenter (hDlg) ; ! 155: } // OnInitDialog ! 156: ! 157: ! 158: void OnStart (HDLG hDlg) ! 159: /* ! 160: Effect: Handle any actions necessary when the user clicks on ! 161: the "Start/Stop" button. ! 162: ! 163: Note: This button could be displaying start or stop, depending ! 164: on the situation. ! 165: */ ! 166: { ! 167: PLOG pLog ; ! 168: ! 169: pLog = LogData (hDlg) ; ! 170: ! 171: bStopButtonClicked = FALSE ; ! 172: switch (pLog->iStatus) ! 173: { // switch ! 174: case iPMStatusClosed: ! 175: if (PlayingBackLog ()) ! 176: { ! 177: bNeedToRelogData = TRUE ; ! 178: } ! 179: else ! 180: { ! 181: FLOAT eTimeInterval ; ! 182: ! 183: eTimeInterval = DialogFloat (hDlg, IDD_LOGOPTINTERVAL, NULL) ; ! 184: if (eTimeInterval > MAX_INTERVALSEC || ! 185: eTimeInterval < MIN_INTERVALSEC) ! 186: { ! 187: DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ; ! 188: SetFocus (DialogControl (hDlg, IDD_LOGOPTINTERVAL)) ; ! 189: EditSetTextEndPos (hDlg, IDD_LOGOPTINTERVAL) ; ! 190: return ; ! 191: break ; ! 192: } ! 193: ! 194: eTimeInterval = eTimeInterval * (FLOAT) 1000.0 + (FLOAT) 0.5 ; ! 195: pLog->iIntervalMSecs = (DWORD) eTimeInterval ; ! 196: ! 197: iIntervalMSecs = pLog->iIntervalMSecs ; ! 198: bNeedToStartLog = TRUE ; ! 199: } ! 200: break ; ! 201: ! 202: case iPMStatusCollecting: ! 203: case iPMStatusPaused: ! 204: CloseLog (hWndLog, pLog) ; ! 205: bStopButtonClicked = TRUE ; ! 206: break ; ! 207: } // switch ! 208: ! 209: ! 210: SimulateButtonPush (hDlg, IDD_OK) ; ! 211: } ! 212: ! 213: ! 214: BOOL static OnOK (HDLG hDlg) ! 215: /* ! 216: Effect: Perform any hooked actions needed when the user selects ! 217: OK in the log options dialog. In particular, if we are ! 218: currently logging, record the need to relog and CANCEL ! 219: the dialog, never letting the real dialog proc get the ! 220: OK. Remember, this is actually a file open dialog that ! 221: we have perverted. If we let the OK through, the common ! 222: dialog manager will try to open it and it will inform ! 223: the user that the file is locked. This way, we let the ! 224: user click OK, but the dialog thinks we cancelled. ! 225: ! 226: Called By: LogOptionsHookProc only. ! 227: ! 228: Returns: Whether the message was handled by this function or not. ! 229: */ ! 230: { // OnOK ! 231: PLOG pLog ; ! 232: ! 233: pLog = LogData (hWndLog) ; ! 234: if (pLog->iStatus == iPMStatusCollecting || ! 235: pLog->iStatus == iPMStatusPaused) ! 236: { ! 237: if (LocalManualRefresh != pLog->bManualRefresh) ! 238: { ! 239: if (!LocalManualRefresh) ! 240: { ! 241: FLOAT eTimeInterval ; ! 242: ! 243: eTimeInterval = DialogFloat (hDlg, IDD_LOGOPTINTERVAL, NULL) ; ! 244: ! 245: if (eTimeInterval > MAX_INTERVALSEC || ! 246: eTimeInterval < MIN_INTERVALSEC) ! 247: { ! 248: DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ; ! 249: SetFocus (DialogControl (hDlg, IDD_LOGOPTINTERVAL)) ; ! 250: EditSetTextEndPos (hDlg, IDD_LOGOPTINTERVAL) ; ! 251: return (FALSE) ; ! 252: } ! 253: ! 254: eTimeInterval = eTimeInterval * (FLOAT) 1000.0 + (FLOAT) 0.5 ; ! 255: pLog->iIntervalMSecs = (DWORD) eTimeInterval ; ! 256: iIntervalMSecs = pLog->iIntervalMSecs ; ! 257: UpdateLogDisplay (hWndLog) ; ! 258: } ! 259: ToggleLogRefresh (hWndLog) ; ! 260: } ! 261: else ! 262: { ! 263: bNeedToSetTimer = TRUE ; ! 264: bCancelled = -1 ; ! 265: } ! 266: SimulateButtonPush (hDlg, IDD_CANCEL) ; ! 267: return TRUE ; ! 268: } ! 269: else ! 270: { ! 271: if (!LocalManualRefresh) ! 272: { ! 273: FLOAT eTimeInterval ; ! 274: ! 275: eTimeInterval = DialogFloat (hDlg, IDD_LOGOPTINTERVAL, NULL) ; ! 276: ! 277: if (eTimeInterval > MAX_INTERVALSEC || ! 278: eTimeInterval < MIN_INTERVALSEC) ! 279: { ! 280: DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ; ! 281: SetFocus (DialogControl (hDlg, IDD_LOGOPTINTERVAL)) ; ! 282: EditSetTextEndPos (hDlg, IDD_LOGOPTINTERVAL) ; ! 283: return (TRUE) ; ! 284: } ! 285: } ! 286: } ! 287: return FALSE ; ! 288: } // OnOK ! 289: ! 290: ! 291: ! 292: void OnPause (HDLG hDlg) ! 293: { ! 294: } ! 295: ! 296: ! 297: ! 298: BOOL APIENTRY LogOptionsHookProc (HWND hDlg, ! 299: UINT iMessage, ! 300: WPARAM wParam, ! 301: LPARAM lParam) ! 302: { ! 303: BOOL bHandled ; ! 304: ! 305: bHandled = TRUE ; ! 306: ! 307: if (iMessage == msgFILEOK) ! 308: { ! 309: bHandled = OnOK (hDlg) ; ! 310: return (bHandled) ; ! 311: } ! 312: ! 313: switch (iMessage) ! 314: { ! 315: case WM_INITDIALOG: ! 316: OnInitDialog (hDlg) ; ! 317: break ; ! 318: ! 319: case WM_DESTROY: ! 320: ! 321: { ! 322: FLOAT eTimeInterval ; ! 323: ! 324: if (!bCancelled) ! 325: { ! 326: eTimeInterval = DialogFloat (hDlg, IDD_LOGOPTINTERVAL, NULL) ; ! 327: if (eTimeInterval > MAX_INTERVALSEC || ! 328: eTimeInterval < MIN_INTERVALSEC) ! 329: { ! 330: DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ; ! 331: } ! 332: else ! 333: { ! 334: eTimeInterval = eTimeInterval * (FLOAT) 1000.0 + (FLOAT) 0.5 ; ! 335: iIntervalMSecs = (DWORD) eTimeInterval ; ! 336: } ! 337: } ! 338: ! 339: dwCurrentDlgID = 0 ; ! 340: bHandled = FALSE ; ! 341: } ! 342: break ; ! 343: ! 344: case WM_COMMAND: ! 345: switch (wParam) ! 346: { // switch ! 347: case IDD_LOGOPTSTART: ! 348: OnStart (hDlg) ; ! 349: break ; ! 350: ! 351: case IDD_LOGOPTPAUSE: ! 352: OnPause (hDlg) ; ! 353: break ; ! 354: ! 355: case IDD_OK: ! 356: bHandled = OnOK (hDlg) ; ! 357: break ; ! 358: ! 359: case IDD_CANCEL: ! 360: bCancelled += 1 ; ! 361: bHandled = FALSE ; ! 362: break ; ! 363: ! 364: case IDD_LOGOPTIONSPERIODIC: ! 365: if (PlayingBackLog()) ! 366: { ! 367: break ; ! 368: } ! 369: // else fall thru to the following case... ! 370: case IDD_LOGOPTIONSMANUALREFRESH: ! 371: // check if the Manual refresh is currently checked. ! 372: // Then toggle the ManualRefresh button ! 373: LocalManualRefresh = ! 374: IsDlgButtonChecked (hDlg, IDD_LOGOPTIONSMANUALREFRESH) ; ! 375: CheckRadioButton (hDlg, ! 376: IDD_LOGOPTIONSMANUALREFRESH, ! 377: IDD_LOGOPTIONSPERIODIC, ! 378: LocalManualRefresh ? IDD_LOGOPTIONSPERIODIC : ! 379: IDD_LOGOPTIONSMANUALREFRESH) ; ! 380: ! 381: DialogEnable (hDlg, IDD_LOGOPTINTERVAL, LocalManualRefresh) ; ! 382: DialogEnable (hDlg, IDD_LOGOPTINTERVALTEXT, LocalManualRefresh) ; ! 383: LocalManualRefresh = !LocalManualRefresh ; ! 384: break ; ! 385: ! 386: case ID_HELP: ! 387: CallWinHelp (dwCurrentDlgID) ; ! 388: break ; ! 389: ! 390: default: ! 391: bHandled = FALSE ; ! 392: break ; ! 393: } // switch ! 394: break; ! 395: ! 396: default: ! 397: bHandled = FALSE ; ! 398: break; ! 399: } // switch ! 400: ! 401: return (bHandled) ; ! 402: } // LogOptionsHookProc ! 403: ! 404: ! 405: BOOL DisplayLogOptions (HWND hWndParent, ! 406: HWND hWndLog) ! 407: ! 408: { // DisplayLogOptions ! 409: TCHAR szFilePath [FilePathLen + 1] ; ! 410: TCHAR szFileTitle [FilePathLen + 1] ; ! 411: TCHAR szFileDirectory [FilePathLen + 1] ; ! 412: TCHAR szCaption [WindowCaptionLen + 1] ; ! 413: OPENFILENAME ofn ; ! 414: PLOG pLog ; ! 415: int RetCode ; ! 416: int PrevLogSize ; ! 417: BOOL bSameFile ; ! 418: ! 419: TCHAR szFilter[LongTextLen] ; ! 420: int StringLength ; ! 421: ! 422: StringLoad (IDS_SAVELOGFILE, szFilter) ; ! 423: StringLength = lstrlen (szFilter) + 1 ; ! 424: LoadString (hInstance, IDS_SAVELOGFILEEXT, ! 425: &szFilter[StringLength], sizeof(szFilter)-StringLength) ; ! 426: StringLength += lstrlen (&szFilter[StringLength]) ; ! 427: szFilter[StringLength+1] = szFilter[StringLength+2] = TEXT('\0') ; ! 428: ! 429: // This dialog is used to change attributes for an existing log file, ! 430: // and to select the name of a log file to open. Therefore we have ! 431: // different options in these cases. ! 432: ! 433: pLog = LogData (hWndLog) ; ! 434: if (!strempty (pLog->szFilePath)) ! 435: { ! 436: FileNameExtension (pLog->szFilePath, szFileTitle) ; ! 437: FileDriveDirectory (pLog->szFilePath, szFileDirectory) ; ! 438: lstrcpy (szFilePath, szFileTitle) ; ! 439: } ! 440: else ! 441: { ! 442: szFileTitle[0] = szFileDirectory[0] = TEXT('\0') ; ! 443: StringLoad (IDS_SAVELOGFILEEXT, szFilePath) ; ! 444: } ! 445: ! 446: StringLoad (IDS_LOGOPTIONS, szCaption) ; ! 447: ! 448: ofn.lStructSize = sizeof(OPENFILENAME) ; ! 449: ofn.hwndOwner = hWndParent ; ! 450: ofn.hInstance = hInstance ; ! 451: ofn.lpstrFilter = szFilter; ! 452: ofn.lpstrCustomFilter = (LPTSTR) NULL; ! 453: ofn.nMaxCustFilter = 0L; ! 454: ofn.nFilterIndex = 1L; ! 455: ofn.lpstrFile = szFilePath ; ! 456: ofn.nMaxFile = FilePathLen ; ! 457: ofn.lpstrFileTitle = szFileTitle ; ! 458: ofn.nMaxFileTitle = FilePathLen ; ! 459: ofn.lpstrInitialDir = szFileDirectory ; ! 460: ofn.lpstrTitle = (LPTSTR) szCaption ; ! 461: ofn.Flags = LogOptionsOFNStyle ; ! 462: ofn.nFileOffset = 0; ! 463: ofn.nFileExtension = 0; ! 464: ofn.lpstrDefExt = (LPTSTR) NULL; ! 465: ofn.lpfnHook = (LPOFNHOOKPROC) LogOptionsHookProc ; ! 466: ofn.lpTemplateName = idDlgLogOptions ; ! 467: ! 468: bNeedToRelogData = FALSE; ! 469: bNeedToStartLog = FALSE ; ! 470: bNeedToSetTimer = FALSE ; ! 471: bStopButtonClicked = FALSE ; ! 472: ! 473: if (GetSaveFileName(&ofn) && !bStopButtonClicked) ! 474: { ! 475: pLog = LogData (hWndLog) ; ! 476: ! 477: // save previous log file name & size ! 478: // so we can reset if error ! 479: PrevLogSize = pLog->lFileSize ; ! 480: ! 481: lstrcpy (szFileTitle, pLog->szFilePath) ; ! 482: ! 483: bSameFile = pstrsamei (pLog->szFilePath, ofn.lpstrFile) ; ! 484: ! 485: if (!bSameFile) ! 486: { ! 487: lstrcpy (pLog->szFilePath, ofn.lpstrFile) ; ! 488: } ! 489: ! 490: pLog->iIntervalMSecs = iIntervalMSecs ; ! 491: ! 492: if (bNeedToStartLog) ! 493: { ! 494: pLog->bManualRefresh = LocalManualRefresh ; ! 495: StartLog (hWndLog, pLog, bSameFile) ; ! 496: } ! 497: else if (bNeedToRelogData) ! 498: { ! 499: bNeedToRelogData = FALSE ; ! 500: SetHourglassCursor() ; ! 501: ReLog (hWndLog, bSameFile) ; ! 502: SetArrowCursor() ; ! 503: } ! 504: else if (LocalManualRefresh != pLog->bManualRefresh) ! 505: { ! 506: ToggleLogRefresh (hWndLog) ; ! 507: } ! 508: ! 509: if (!pLog->hFile) ! 510: { ! 511: if (bNeedToStartLog) ! 512: { ! 513: // if we get here, that means StartLog has detected ! 514: // problem, just restore the old stuff.. ! 515: pLog->lFileSize = PrevLogSize ; ! 516: lstrcpy (pLog->szFilePath, szFileTitle) ; ! 517: } ! 518: // verify if this is a good log file and setup the file size ! 519: else if ((RetCode = CreateLogFile (pLog, FALSE, bSameFile)) != 0) ! 520: { ! 521: DlgErrorBox (hWndLog, RetCode, pLog->szFilePath); ! 522: pLog->lFileSize = PrevLogSize ; ! 523: lstrcpy (pLog->szFilePath, szFileTitle) ; ! 524: } ! 525: else ! 526: { ! 527: // unfortunately, we have to close this file. ! 528: // Otherwise, when we do StartLog, the common dialog ! 529: // will complain that this file is already in-used. ! 530: CloseHandle (pLog->hFile) ; ! 531: } ! 532: pLog->hFile = 0 ; ! 533: } ! 534: ! 535: UpdateLogDisplay (hWndLog) ; ! 536: } ! 537: ! 538: ! 539: // Remember, we faked out GetSaveFileName to return FALSE. See OnOK doc. ! 540: if (bNeedToSetTimer) ! 541: { ! 542: SetLogTimer (hWndLog, iIntervalMSecs) ; ! 543: UpdateLogDisplay (hWndLog) ; ! 544: } ! 545: ! 546: return (TRUE) ; ! 547: } // DisplayLogOptions ! 548: ! 549: ! 550: ! 551:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.