home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / winnt / perfmon / export.c < prev    next >
Text File  |  1995-10-29  |  8KB  |  272 lines

  1. #include "perfmon.h"
  2. #include <lmcons.h>
  3. #include <lmerr.h>
  4. #include <lmapibuf.h>
  5. #include <lmwksta.h>
  6. // #include <uiexport.h>
  7. #include <stdio.h>         // for sprintf
  8. #include "utils.h"
  9.  
  10. #include "perfmops.h"      // for SystemTimeDateString
  11. #include "fileopen.h"      // for FileGetName
  12. #include "fileutil.h"      // for FileRead etc
  13. #include "playback.h"      // for PlayingBackLog & LogPositionSystemTime
  14. #include "dlgs.h"          // common dialog control IDs
  15. #include "pmhelpid.h"      // Help IDs
  16.  
  17.  
  18. // This routine opens the export file and put in the header info.
  19. // It is used by ExportChart, ExportAlert, & ExportReport.
  20. INT  ExportFileOpen (HWND hWnd, HANDLE *phFile, int IntervalMSecs, LPTSTR *ppFileName)
  21. {
  22.    CHAR           TempBuff [LongTextLen * 2] ;
  23.  
  24.    TCHAR          UnicodeBuff [LongTextLen] ;
  25.    TCHAR          UnicodeBuff1 [MiscTextLen] ;
  26.    SYSTEMTIME     SystemTime ;
  27.    int            StringLen ;
  28.    INT            ErrCode = 0 ;
  29.    FLOAT          eIntervalSecs ;
  30.  
  31.    // defined and setup in status.c
  32.    extern TCHAR   szCurrentActivity [] ;
  33.    extern TCHAR   szStatusFormat [] ;
  34.  
  35.    *phFile = 0 ;
  36.  
  37.    if (!FileGetName (hWnd, IDS_EXPORTFILE, UnicodeBuff))
  38.       {
  39.       // user cancel 
  40.       goto Exit0 ;
  41.       }
  42.  
  43.    *ppFileName = StringAllocate (UnicodeBuff) ;
  44.  
  45.    // open the file..
  46.    if (!(*phFile = FileHandleCreate (UnicodeBuff)))
  47.       {
  48.       // can't open the file
  49.       ErrCode = ERR_CANT_OPEN ;
  50.       goto Exit0 ;
  51.       }
  52.  
  53.  
  54.    // export header
  55.    StringLoad (IDS_REPORT_HEADER, UnicodeBuff) ;
  56.    ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  57.    StringLen = strlen (TempBuff) ;
  58.    ConvertUnicodeStr (&TempBuff[StringLen], LocalComputerName) ;
  59.    strcat (TempBuff, LineEndStr) ;
  60.  
  61.    if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  62.       {
  63.       ErrCode = ERR_EXPORT_FILE ;
  64.       goto Exit0 ;
  65.       }
  66.  
  67.    // export today's date time
  68.    GetLocalTime (&SystemTime) ;
  69.  
  70.    StringLoad (IDS_EXPORT_DATE, UnicodeBuff) ;
  71.    StringLen = lstrlen (UnicodeBuff) ;
  72.    UnicodeBuff[StringLen] = TEXT(':') ;
  73.    UnicodeBuff[StringLen+1] = TEXT(' ') ;
  74.    SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen+2]) ;
  75.    ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  76.    strcat (TempBuff, LineEndStr) ;
  77.  
  78.    if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  79.       {
  80.       ErrCode = ERR_EXPORT_FILE ;
  81.       goto Exit0 ;
  82.       }
  83.  
  84.    StringLoad (IDS_EXPORT_TIME, UnicodeBuff) ;
  85.    StringLen = lstrlen (UnicodeBuff) ;
  86.    UnicodeBuff[StringLen] = TEXT(':') ;
  87.    UnicodeBuff[StringLen+1] = TEXT(' ') ;
  88.    SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen+2], FALSE) ;
  89.    ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  90.    strcat (TempBuff, LineEndStr) ;
  91.  
  92.    if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  93.       {
  94.       ErrCode = ERR_EXPORT_FILE ;
  95.       goto Exit0 ;
  96.       }
  97.  
  98.  
  99.    // export data source
  100.    TSPRINTF (UnicodeBuff, szStatusFormat,
  101.       PlayingBackLog () ?
  102.       PlaybackLog.szFileTitle : szCurrentActivity) ;
  103.    ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  104.    strcat (TempBuff, LineEndStr) ;
  105.    
  106.    if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  107.       {
  108.       ErrCode = ERR_EXPORT_FILE ;
  109.       goto Exit0 ;
  110.       }
  111.  
  112.  
  113.    if (!PlayingBackLog())
  114.       {
  115.          
  116.       eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ;
  117.       StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ;
  118.       TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ;
  119.       ConvertDecimalPoint (UnicodeBuff) ;
  120.       ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  121.       strcat (TempBuff, LineEndStr) ;
  122.    
  123.       if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  124.          {
  125.  
  126.          ErrCode = ERR_EXPORT_FILE ;
  127.          goto Exit0 ;
  128.          }
  129.       }
  130.    else
  131.       {
  132.       // export the log start and stop date/time
  133.       StringLoad (IDS_START_TEXT, UnicodeBuff) ;
  134.       StringLen = lstrlen (UnicodeBuff) ;
  135.       LogPositionSystemTime (&(PlaybackLog.StartIndexPos), &SystemTime) ;
  136.       SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ;
  137.       StringLen = lstrlen (UnicodeBuff) ;
  138.       UnicodeBuff[StringLen] = TEXT(' ') ;
  139.       StringLen++ ;
  140.       SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen], FALSE) ;
  141.       ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  142.       strcat (TempBuff, LineEndStr) ;
  143.  
  144.       if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  145.          {
  146.  
  147.          ErrCode = ERR_EXPORT_FILE ;
  148.          goto Exit0 ;
  149.          }
  150.  
  151.       StringLoad (IDS_STOP_TEXT, UnicodeBuff) ;
  152.       StringLen = lstrlen (UnicodeBuff) ;
  153.       LogPositionSystemTime (&(PlaybackLog.StopIndexPos), &SystemTime) ;
  154.       SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ;
  155.       StringLen = lstrlen (UnicodeBuff) ;
  156.       UnicodeBuff[StringLen] = TEXT(' ') ;
  157.       StringLen++ ;
  158.       SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen], FALSE) ;
  159.       ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  160.       strcat (TempBuff, LineEndStr) ;
  161.  
  162.       if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  163.          {
  164.          ErrCode = ERR_EXPORT_FILE ;
  165.          goto Exit0 ;
  166.          }
  167.  
  168.       if (hWnd == hWndAlert)
  169.          {
  170.          eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ;
  171.          StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ;
  172.          TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ;
  173.          ConvertDecimalPoint (UnicodeBuff) ;
  174.          ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  175.          strcat (TempBuff, LineEndStr) ;
  176.       
  177.          if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  178.             {
  179.             ErrCode = ERR_EXPORT_FILE ;
  180.             goto Exit0 ;
  181.             }
  182.          }
  183.       
  184.       }
  185.  
  186.    return (0) ;
  187.  
  188. Exit0:
  189.  
  190.    return (ErrCode) ;
  191.  
  192. }  // ExportFileOpen
  193.  
  194.  
  195.  
  196. BOOL APIENTRY ExportOptionsHookProc (HWND hDlg, 
  197.                                      UINT iMessage, 
  198.                                      WPARAM wParam, 
  199.                                      LPARAM lParam)
  200.  
  201. {
  202.    BOOL           bHandled ;
  203.  
  204.    bHandled = TRUE ;
  205.    switch (iMessage)
  206.       {
  207.       case WM_INITDIALOG:
  208.          CheckRadioButton (hDlg, IDD_EXPORTCOMMAS, IDD_EXPORTTAB,
  209.             pDelimiter == TabStr ? IDD_EXPORTTAB : IDD_EXPORTCOMMAS ) ;
  210.  
  211.          WindowCenter (hDlg) ;
  212.          break ;
  213.  
  214.       case WM_COMMAND:
  215.          switch (LOWORD(wParam))
  216.             {  // switch
  217.             case IDD_EXPORTCOMMAS:
  218.             case IDD_EXPORTTAB:
  219.                // toggle between the 2 radio buttons..
  220.                CheckRadioButton (hDlg, IDD_EXPORTCOMMAS, IDD_EXPORTTAB,
  221.                    LOWORD(wParam) == IDD_EXPORTTAB ?
  222.                      IDD_EXPORTTAB : IDD_EXPORTCOMMAS ) ;
  223.                break ;
  224.  
  225.             case IDD_OK:
  226.                pDelimiter = IsDlgButtonChecked (hDlg, IDD_EXPORTCOMMAS) ?
  227.                   CommasStr : TabStr ;
  228.                bHandled = FALSE ;
  229.  
  230.                break ;
  231.  
  232.             case IDD_EXPORTHELP:
  233.                CallWinHelp (dwCurrentDlgID) ;
  234.                break ;
  235.  
  236.             case cmb1:
  237.                if (HIWORD (wParam) == CBN_SELCHANGE)
  238.                   {
  239.                   int   iFileIndex ;
  240.                   HWND  hWndCBox = (HWND) lParam ;
  241.  
  242.                   // a diff. selection from the file type, change
  243.                   // the delimiter accordingly.
  244.                   iFileIndex = CBSelection (hWndCBox) ;
  245.                   CheckRadioButton (hDlg, IDD_EXPORTCOMMAS, IDD_EXPORTTAB,
  246.                      iFileIndex == 0 ?
  247.                      IDD_EXPORTTAB : IDD_EXPORTCOMMAS ) ;
  248.  
  249.                   }
  250.                else
  251.                   {
  252.                   bHandled = FALSE ;
  253.                   }
  254.                break ;
  255.  
  256.             default:
  257.                bHandled = FALSE ;
  258.             }  // switch
  259.          break;
  260.  
  261.       default:
  262.          bHandled = FALSE ;
  263.          break;            
  264.       }  // switch
  265.  
  266.    return (bHandled) ;
  267.  
  268. }  // ExportOptionsHookProc
  269.  
  270. 
  271. 
  272.