Annotation of mstools/samples/sdktools/perfmon/datasrc.c, revision 1.1.1.1

1.1       root        1: 
                      2: //==========================================================================//
                      3: //                                  Includes                                //
                      4: //==========================================================================//
                      5: 
                      6: #include "perfmon.h"
                      7: #include "datasrc.h"       // External declarations for this file
                      8: 
                      9: #include "fileutil.h"      // for FileErrorMessageBox (whatever)
                     10: #include "grafdata.h"      // for ResetGraph
                     11: #include "alert.h"         // for ResetAlert
                     12: #include "log.h"           // for ResetLog
                     13: #include "report.h"        // for ResetReport
                     14: #include "playback.h"
                     15: #include "status.h"
                     16: #include "utils.h"
                     17: #include "pmhelpid.h"      // Help IDs
                     18: #include "fileopen.h"      // FileOpneHookProc
                     19: #include "pmemory.h"       // for MemoryAllocate & MemoryFree
                     20: 
                     21: //==========================================================================//
                     22: //                                Local Data                                //
                     23: //==========================================================================//
                     24: 
                     25: 
                     26: BOOL           bIgnoreFirstChange ;
                     27: BOOL           bDataSourceNow ;
                     28: BOOL           bDataSourcePrevious ;
                     29: BOOL           bLogFileNameChanged ;
                     30: 
                     31: LPTSTR           pszLogFilePath ;
                     32: LPTSTR           pszLogFileTitle ;
                     33: 
                     34: 
                     35: //==========================================================================//
                     36: //                              Local Functions                             //
                     37: //==========================================================================//
                     38: 
                     39: 
                     40: 
                     41: void static UpdateLogName (HDLG hDlg)
                     42:    {
                     43:    DialogSetString (hDlg, IDD_DATASOURCEFILENAME, pszLogFileTitle) ;
                     44:    }
                     45: 
                     46: 
                     47: 
                     48: void OnChangeLog (HWND hWndParent)
                     49:    {  // OnChangeLog
                     50:    OPENFILENAME   ofn ;
                     51:    TCHAR          szOpenLog [WindowCaptionLen + 1] ;
                     52:    TCHAR          aszOpenFilter[LongTextLen] ;
                     53:    TCHAR          szMyLogFilePath [FilePathLen + 1] ;
                     54:    int            StringLength ;
                     55:    DWORD          SaveCurrentDlgID = dwCurrentDlgID ;
                     56: 
                     57:    //=============================//
                     58:    // Get Log File                //
                     59:    //=============================//
                     60: 
                     61:    StringLoad (IDS_OPENLOG, szOpenLog) ;
                     62:    StringLoad (IDS_SAVELOGFILEEXT, szMyLogFilePath) ;
                     63: 
                     64:    // load the log file extension
                     65:    LoadString (hInstance, IDS_SAVELOGFILE, aszOpenFilter,
                     66:       sizeof(aszOpenFilter) / sizeof(TCHAR)) ;
                     67:    StringLength = lstrlen (aszOpenFilter) + 1 ;
                     68:    LoadString (hInstance, IDS_SAVELOGFILEEXT,
                     69:       &aszOpenFilter[StringLength],
                     70:       sizeof(aszOpenFilter) / sizeof(TCHAR) - StringLength) ;
                     71:    StringLength += lstrlen (&aszOpenFilter[StringLength]) ;
                     72: 
                     73:    // setup the end strings
                     74:    aszOpenFilter[StringLength+1] = aszOpenFilter[StringLength+2] = TEXT('\0') ;
                     75: 
                     76: 
                     77:    ofn.lStructSize = sizeof (OPENFILENAME) ;
                     78:    ofn.hwndOwner = hWndParent ;
                     79:    ofn.hInstance = hInstance ;
                     80:    ofn.lpstrFilter = aszOpenFilter ;
                     81:    ofn.lpstrCustomFilter = NULL ;
                     82:    ofn.nMaxCustFilter = 0 ;
                     83:    ofn.nFilterIndex = 1;
                     84:    ofn.lpstrFile = szMyLogFilePath ;
                     85:    ofn.nMaxFile = FilePathLen * sizeof (TCHAR) ;   
                     86:    ofn.lpstrFileTitle = pszLogFileTitle ;
                     87:    ofn.nMaxFileTitle = FilePathLen * sizeof (TCHAR) ;
                     88:    ofn.lpstrInitialDir = NULL ;
                     89:    ofn.lpstrTitle = szOpenLog ;
                     90:    ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | 
                     91:                OFN_PATHMUSTEXIST | OFN_SHOWHELP  | OFN_ENABLEHOOK ;
                     92:    ofn.lCustData = 0L ;
                     93:    ofn.lpfnHook = (LPOFNHOOKPROC) FileOpenHookProc ;
                     94:    ofn.lpstrDefExt = (LPTSTR)NULL;
                     95: 
                     96:    dwCurrentDlgID  = HC_PM_idDlgOptionOpenLogFile ;
                     97:    if (GetOpenFileName (&ofn))
                     98:       {
                     99:       if (!strsame(pszLogFilePath, szMyLogFilePath))
                    100:          {
                    101:          int    FileNameOffset ;
                    102:          LPTSTR pFileName ;
                    103: 
                    104:          bLogFileNameChanged |= TRUE ;
                    105:          lstrcpy (pszLogFilePath, szMyLogFilePath) ;
                    106:          lstrcpy (pszLogFileTitle, ofn.lpstrFileTitle) ;
                    107: 
                    108:          pFileName = ExtractFileName (szMyLogFilePath) ;
                    109:          if (pFileName != szMyLogFilePath)
                    110:             {
                    111:             FileNameOffset = pFileName - szMyLogFilePath ;
                    112:             szMyLogFilePath[FileNameOffset] = TEXT('\0') ;
                    113:             SetCurrentDirectory (szMyLogFilePath) ;
                    114:             }
                    115:          UpdateLogName (hWndParent) ;
                    116:          }
                    117:       }
                    118: 
                    119:    // restore the global before exit
                    120:    dwCurrentDlgID  = SaveCurrentDlgID ;
                    121:    }  // OnChangeLog
                    122: 
                    123: 
                    124: //==========================================================================//
                    125: //                              Message Handlers                            //
                    126: //==========================================================================//
                    127: 
                    128: 
                    129: void static OnInitDialog (HDLG hDlg)
                    130:    {
                    131:    bLogFileNameChanged = FALSE ;
                    132: 
                    133:    bIgnoreFirstChange = TRUE ;
                    134: 
                    135:    bDataSourcePrevious = bDataSourceNow = !PlayingBackLog () ;
                    136: 
                    137:    CheckRadioButton (hDlg, IDD_DATASOURCENOW, IDD_DATASOURCEFILE,
                    138:                      bDataSourceNow ? IDD_DATASOURCENOW : IDD_DATASOURCEFILE) ;
                    139:    UpdateLogName (hDlg) ;
                    140: 
                    141:    EditSetLimit (GetDlgItem(hDlg, IDD_DATASOURCEFILENAME),
                    142:       FilePathLen - 1) ;
                    143: 
                    144:    WindowCenter (hDlg) ;
                    145: 
                    146:    dwCurrentDlgID = HC_PM_idDlgOptionDataFrom ;
                    147:    }
                    148: 
                    149: 
                    150: void /*static*/ OnDataSourceOK (HDLG hDlg)
                    151:    {  // OnOK
                    152:    BOOL     bHaveResetPerfmon ;
                    153:    INT      RetCode = 0 ;
                    154: 
                    155:    bHaveResetPerfmon = FALSE;
                    156:    if (!BoolEqual (bDataSourceNow, bDataSourcePrevious) ||
                    157:        (bLogFileNameChanged && !bDataSourceNow) )
                    158:       {
                    159:       if (PlayingBackLog () && bDataSourceNow | bLogFileNameChanged)
                    160:          {
                    161:          CloseInputLog (hWndMain) ;
                    162:          bHaveResetPerfmon = TRUE ;
                    163:          }
                    164: 
                    165:       if (!bDataSourceNow)
                    166:          {
                    167:          if (!bHaveResetPerfmon)
                    168:             {
                    169:             ResetGraphView (hWndGraph) ;
                    170:             ResetAlertView (hWndAlert) ;
                    171:             ResetLogView (hWndLog) ;
                    172:             ResetReportView (hWndReport) ;
                    173:             }
                    174: 
                    175:          GetDlgItemText (hDlg, IDD_DATASOURCEFILENAME,
                    176:             pszLogFilePath, FilePathLen - 1) ;         
                    177:          lstrcpy (pszLogFileTitle, pszLogFilePath);
                    178:    
                    179:          if (RetCode = OpenPlayback (pszLogFilePath, pszLogFileTitle))
                    180:             {
                    181:             DlgErrorBox (hDlg, RetCode, pszLogFileTitle) ;
                    182:             }
                    183:          }
                    184: 
                    185:       StatusLineReady (hWndStatus) ;
                    186:       }
                    187: 
                    188:    if (RetCode == 0)
                    189:       {
                    190:       EndDialog (hDlg, 1) ;
                    191:       }
                    192:    }  // OnOK      
                    193: 
                    194: 
                    195: 
                    196: //==========================================================================//
                    197: //                             Exported Functions                           //
                    198: //==========================================================================//
                    199: 
                    200: 
                    201: int FAR WINAPI DataSourceDlgProc (HWND hDlg, 
                    202:                                   unsigned iMessage, 
                    203:                                   WPARAM wParam, 
                    204:                                   LPARAM lParam)
                    205:    {
                    206:    BOOL           bHandled ;
                    207: 
                    208:    bHandled = TRUE ;
                    209:    switch (iMessage)
                    210:       {
                    211:       case WM_INITDIALOG:
                    212:          OnInitDialog (hDlg) ;
                    213:          return  (TRUE) ;
                    214: 
                    215:       case WM_CLOSE:
                    216:          dwCurrentDlgID = 0 ;
                    217:          EndDialog (hDlg, 0) ;
                    218:          break ;
                    219: 
                    220:       case WM_COMMAND:
                    221:          switch(LOWORD(wParam))
                    222:             {
                    223:             case IDD_DATASOURCEFILENAME:
                    224:                if (bIgnoreFirstChange)
                    225:                   {
                    226:                   bIgnoreFirstChange = FALSE;
                    227:                   }
                    228: 
                    229:                else if (HIWORD(wParam) == EN_UPDATE && !bLogFileNameChanged) 
                    230:                   {
                    231:                   bLogFileNameChanged = TRUE;
                    232:                   CheckRadioButton (hDlg,
                    233:                                   IDD_DATASOURCENOW,
                    234:                                   IDD_DATASOURCEFILE,
                    235:                                   IDD_DATASOURCEFILE) ;
                    236:                   bDataSourceNow = FALSE ;
                    237:                   }
                    238:                break ;
                    239: 
                    240:             case IDD_DATASOURCECHANGEFILE:
                    241:                OnChangeLog (hDlg) ;
                    242:                if (bLogFileNameChanged)
                    243:                   {
                    244:                   CheckRadioButton (hDlg,
                    245:                                     IDD_DATASOURCENOW,
                    246:                                     IDD_DATASOURCEFILE,
                    247:                                     IDD_DATASOURCEFILE) ;
                    248:                   bDataSourceNow = FALSE ;
                    249:                   }
                    250:                break ;
                    251: 
                    252:             case IDD_DATASOURCEFILE:
                    253:                bDataSourceNow = FALSE ;
                    254:                break ;
                    255: 
                    256:             case IDD_DATASOURCENOW:
                    257:                bDataSourceNow = TRUE ;
                    258:                break ;
                    259: 
                    260:             case IDD_OK:
                    261:                dwCurrentDlgID = 0 ;
                    262:                OnDataSourceOK (hDlg) ;
                    263:                break ;
                    264: 
                    265:             case IDD_CANCEL:
                    266:                dwCurrentDlgID = 0 ;
                    267:                EndDialog (hDlg, 0) ;
                    268:                break ;
                    269: 
                    270:             case IDD_DATASOURCEHELP:
                    271:                CallWinHelp (dwCurrentDlgID) ;
                    272:                break ;
                    273: 
                    274:             default:
                    275:                bHandled = FALSE ;
                    276:                break;
                    277:             }
                    278:          break;
                    279: 
                    280: 
                    281:       default:
                    282:             bHandled = FALSE ;
                    283:          break ;            
                    284:       }  // switch
                    285: 
                    286:    return (bHandled) ;
                    287:    }  // DataSourceDlgProc
                    288: 
                    289: 
                    290: 
                    291: BOOL DisplayDataSourceOptions (HWND hWndParent)
                    292: /*
                    293:    Effect:        Put up Perfmon's Data Source Options Display dialog,
                    294:                   which allows
                    295:                   the user to select the source of data input: real
                    296:                   time or log file.
                    297: */
                    298:    {  // DisplayDisplayOptions
                    299:    BOOL     retCode ;
                    300: 
                    301:    pszLogFilePath  = (LPTSTR) MemoryAllocate (FilePathLen * sizeof(TCHAR)) ;
                    302:    pszLogFileTitle = (LPTSTR) MemoryAllocate (FilePathLen * sizeof(TCHAR)) ;
                    303:    
                    304:    lstrcpy (pszLogFilePath, PlaybackLog.szFilePath) ;
                    305:    lstrcpy (pszLogFileTitle, PlaybackLog.szFileTitle) ;
                    306: 
                    307:    retCode = DialogBox (hInstance, idDlgDataSource,
                    308:                       hWndParent, (DLGPROC) DataSourceDlgProc) ;
                    309: 
                    310:    MemoryFree (pszLogFilePath) ;
                    311:    MemoryFree (pszLogFileTitle) ;
                    312: 
                    313:    return (retCode) ;
                    314: 
                    315:    }  // DisplayDisplayOptions
                    316: 
                    317: 
                    318: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.