DIALOGS.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:18k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*****************************************************************************
  2.  *
  3.  *  Dialogs.c - This module handles the Menu and Dialog user interactions.
  4.  *
  5.  *  Microsoft Confidential
  6.  *  Copyright (c) 1992-1997 Microsoft Corporation
  7.  *
  8.  ****************************************************************************/
  9. #include <stdio.h>
  10. #include <wchar.h>   // for swscanf
  11. #include "perfmon.h"
  12. #include "perfmops.h"      // for ConvertDecimalPoint
  13. #include "alert.h"     // for SetAlertTimer, AlertData
  14. #include "graph.h"
  15. #include "cderr.h"
  16. #include "utils.h"
  17. #include "playback.h"  // for PlayingBackLog
  18. #include "grafdisp.h"  // for ToggleGraphRefresh
  19. #include "pmhelpid.h"  // Help IDs
  20. BOOL          LocalManualRefresh ;
  21. /***************************************************************************/
  22. BOOL FAR PASCAL GraphOptionDlg(HWND hDlg, WORD msg, DWORD wParam, LONG lParam)
  23. /***************************************************************************/
  24. {
  25. static GRAPH_OPTIONS goLocalCopy ;
  26. INT            iTimeMilliseconds ;
  27. TCHAR          szBuff[MiscTextLen] ;
  28. PGRAPHSTRUCT   lgraph;
  29.    lParam ;
  30.    lgraph = pGraphs;
  31.    switch(msg)
  32.       {
  33.       case WM_INITDIALOG:
  34.          dwCurrentDlgID = HC_PM_idDlgOptionChart ;
  35.          // Init the Radio button, Check boxes and text fields.
  36.          goLocalCopy.iGraphOrHistogram =
  37.             lgraph->gOptions.iGraphOrHistogram ;
  38.          if (lgraph->gOptions.iGraphOrHistogram == LINE_GRAPH)
  39.             CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM, ID_GRAPH) ;
  40.          else
  41.             CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM, ID_HISTOGRAM) ;
  42.          CheckDlgButton(hDlg, ID_LEGEND, lgraph->gOptions.bLegendChecked) ;
  43.          if (!(lgraph->gOptions.bLegendChecked))
  44.             {
  45.             // can't display valuebar w/o legend
  46.             DialogEnable (hDlg, IDD_CHARTOPTIONSVALUEBAR, FALSE) ;
  47.             }
  48.          CheckDlgButton(hDlg, ID_LABELS, lgraph->gOptions.bLabelsChecked) ;
  49.          CheckDlgButton(hDlg, ID_VERT_GRID, lgraph->gOptions.bVertGridChecked) ;
  50.          CheckDlgButton(hDlg, ID_HORZ_GRID, lgraph->gOptions.bHorzGridChecked) ;
  51.          CheckDlgButton(hDlg, IDD_CHARTOPTIONSVALUEBAR,
  52.             lgraph->gOptions.bStatusBarChecked) ;
  53.          TSPRINTF(szBuff, TEXT("%d"), lgraph->gOptions.iVertMax) ;
  54.          SendDlgItemMessage(hDlg, ID_VERT_MAX, WM_SETTEXT, 0, (LONG) szBuff) ;
  55.          TSPRINTF(szBuff, TEXT("%3.3f"), lgraph->gOptions.eTimeInterval) ;
  56.          ConvertDecimalPoint (szBuff) ;
  57.          SendDlgItemMessage(hDlg, IDD_CHARTOPTIONSINTERVAL, WM_SETTEXT, 0, (LONG) szBuff) ;
  58.          // Pickup a local copy of the Graph Options.
  59.          goLocalCopy = lgraph->gOptions ;
  60.          LocalManualRefresh = lgraph->bManualRefresh ;
  61.          if (PlayingBackLog())
  62.             {
  63.             DialogEnable (hDlg, IDD_CHARTOPTIONSPERIODIC, FALSE) ;
  64.             DialogEnable (hDlg, IDD_CHARTOPTIONSUPDATETEXT, FALSE) ;
  65.             DialogEnable (hDlg, IDD_CHARTOPTIONSMANUALREFRESH, FALSE) ;
  66.             }
  67.          else
  68.             {
  69.             CheckRadioButton (hDlg,
  70.                IDD_CHARTOPTIONSMANUALREFRESH,
  71.                IDD_CHARTOPTIONSPERIODIC,
  72.                LocalManualRefresh ? IDD_CHARTOPTIONSMANUALREFRESH :
  73.                IDD_CHARTOPTIONSPERIODIC) ;
  74.             }
  75.          if (lgraph->bManualRefresh || PlayingBackLog())
  76.             {
  77.             DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT, FALSE) ;
  78.             DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL, FALSE) ;
  79.             }
  80.          else
  81.             {
  82.             DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT, TRUE) ;
  83.             DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL, TRUE) ;
  84.             }
  85.          EditSetLimit (GetDlgItem(hDlg, ID_VERT_MAX),
  86.             sizeof(szBuff) / sizeof(TCHAR) - 1) ;
  87.          EditSetLimit (GetDlgItem(hDlg, IDD_CHARTOPTIONSINTERVAL),
  88.             ShortTextLen) ;
  89.          WindowCenter (hDlg) ;
  90.          return(TRUE);
  91.       case WM_COMMAND:
  92.          switch(LOWORD(wParam))
  93.             {
  94.             case ID_VERT_MAX:
  95.                if (HIWORD(wParam) == EN_CHANGE)
  96.                   {
  97.                   DialogText(hDlg, ID_VERT_MAX, szBuff) ;
  98.                   swscanf(szBuff, TEXT("%d"), &goLocalCopy.iVertMax) ;
  99.                   }
  100.                break ;
  101.             case IDD_CHARTOPTIONSINTERVAL:
  102.                if (HIWORD(wParam) == EN_CHANGE)
  103.                   {
  104.                   goLocalCopy.eTimeInterval =
  105.                      DialogFloat (hDlg, IDD_CHARTOPTIONSINTERVAL, NULL) ;
  106.                   }
  107.                break ;
  108.             case IDD_CHARTOPTIONSPERIODIC:
  109.             case IDD_CHARTOPTIONSMANUALREFRESH:
  110.                // check if the Manual refresh is currently checked.
  111.                // Then toggle the ManualRefresh button
  112.                LocalManualRefresh =
  113.                   (LOWORD(wParam) == IDD_CHARTOPTIONSMANUALREFRESH) ;
  114.                CheckRadioButton (hDlg,
  115.                   IDD_CHARTOPTIONSMANUALREFRESH,
  116.                   IDD_CHARTOPTIONSPERIODIC,
  117.                   LocalManualRefresh ? IDD_CHARTOPTIONSMANUALREFRESH :
  118.                   IDD_CHARTOPTIONSPERIODIC) ;
  119.                // gray out time interval if necessary...
  120.                DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVALTEXT,
  121.                   !LocalManualRefresh) ;
  122.                DialogEnable (hDlg, IDD_CHARTOPTIONSINTERVAL,
  123.                   !LocalManualRefresh) ;
  124.                break ;
  125.             case IDD_CHARTOPTIONSVALUEBAR:
  126.                if (goLocalCopy.bStatusBarChecked == TRUE)
  127.                   goLocalCopy.bStatusBarChecked = FALSE ;
  128.                else
  129.                   goLocalCopy.bStatusBarChecked = TRUE ;
  130.                break ;
  131.             case ID_LEGEND:
  132.                if (goLocalCopy.bLegendChecked == TRUE)
  133.                   goLocalCopy.bLegendChecked = FALSE ;
  134.                else
  135.                   goLocalCopy.bLegendChecked = TRUE ;
  136.                DialogEnable (hDlg, IDD_CHARTOPTIONSVALUEBAR,
  137.                   goLocalCopy.bLegendChecked) ;
  138.                break ;
  139.             case ID_LABELS:
  140.                if (goLocalCopy.bLabelsChecked == TRUE)
  141.                   goLocalCopy.bLabelsChecked = FALSE ;
  142.                else
  143.                   goLocalCopy.bLabelsChecked = TRUE ;
  144.                break ;
  145.             case ID_VERT_GRID:
  146.                if (goLocalCopy.bVertGridChecked == TRUE)
  147.                   goLocalCopy.bVertGridChecked = FALSE ;
  148.                else
  149.                   goLocalCopy.bVertGridChecked = TRUE ;
  150.                break ;
  151.             case ID_HORZ_GRID:
  152.                if (goLocalCopy.bHorzGridChecked == TRUE)
  153.                   goLocalCopy.bHorzGridChecked = FALSE ;
  154.                else
  155.                   goLocalCopy.bHorzGridChecked = TRUE ;
  156.                break ;
  157.             case ID_GRAPH:
  158.             case ID_HISTOGRAM:
  159.                if (LOWORD(wParam) == ID_GRAPH)
  160.                   {
  161.                   goLocalCopy.iGraphOrHistogram = LINE_GRAPH ;
  162.                   }
  163.                else
  164.                   {
  165.                   goLocalCopy.iGraphOrHistogram = BAR_GRAPH ;
  166.                   }
  167.                CheckRadioButton(hDlg, ID_GRAPH, ID_HISTOGRAM,
  168.                   goLocalCopy.iGraphOrHistogram == LINE_GRAPH ?
  169.                   ID_GRAPH : ID_HISTOGRAM) ;
  170.                break ;
  171.             case IDOK:
  172.                //  verify some numeric entries first
  173.                if (goLocalCopy.iVertMax > MAX_VERTICAL ||
  174.                    goLocalCopy.iVertMax < MIN_VERTICAL)
  175.                   {
  176.                   DlgErrorBox (hDlg, ERR_BADVERTMAX) ;
  177.                   SetFocus (DialogControl (hDlg, ID_VERT_MAX)) ;
  178.                   EditSetTextEndPos (hDlg, ID_VERT_MAX) ;
  179.                   return (FALSE) ;
  180.                   break ;
  181.                   }
  182.                if (goLocalCopy.eTimeInterval > MAX_INTERVALSEC ||
  183.                    goLocalCopy.eTimeInterval < MIN_INTERVALSEC)
  184.                   {
  185.                   DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ;
  186.                   SetFocus (DialogControl (hDlg, IDD_CHARTOPTIONSINTERVAL)) ;
  187.                   EditSetTextEndPos (hDlg, IDD_CHARTOPTIONSINTERVAL) ;
  188.                   return (FALSE) ;
  189.                   break ;
  190.                   }
  191.                // We need to send a size message to the main window
  192.                // so it can setup the redraw of the graph and legend.
  193.                lgraph->gOptions.bLegendChecked    = goLocalCopy.bLegendChecked ;
  194.                lgraph->gOptions.bStatusBarChecked = goLocalCopy.bStatusBarChecked ;
  195.                if (lgraph->gOptions.eTimeInterval != goLocalCopy.eTimeInterval
  196.                   && !LocalManualRefresh)
  197.                   {
  198.                   iTimeMilliseconds = (INT) (goLocalCopy.eTimeInterval * (FLOAT) 1000.0) ;
  199.                   pGraphs->gInterval = iTimeMilliseconds ;
  200.                   if (!PlayingBackLog())
  201.                      {
  202.                      SetGraphTimer(pGraphs) ;
  203.                      }
  204.                   lgraph->bManualRefresh = LocalManualRefresh ;
  205.                   }
  206.                else if (LocalManualRefresh != lgraph->bManualRefresh)
  207.                   {
  208.                   ToggleGraphRefresh (hWndGraph) ;
  209.                   }
  210.                // Assign the local copy of the graph options to the
  211.                // global copy.
  212.                lgraph->gOptions = goLocalCopy ;
  213.                SizeGraphComponents (hWndGraph) ;
  214.                WindowInvalidate (hWndGraph) ;
  215.                dwCurrentDlgID = 0 ;
  216.                EndDialog (hDlg, 1) ;
  217.                return (TRUE) ;
  218.                break ;
  219.             case IDCANCEL:
  220.                dwCurrentDlgID = 0 ;
  221.                EndDialog(hDlg,0);
  222.                return(TRUE);
  223.             case ID_HELP:
  224.                CallWinHelp (dwCurrentDlgID) ;
  225.                break ;
  226.             default:
  227.                break;
  228.             }
  229.          break;
  230.       default:
  231.          break;
  232.       }
  233.    return(FALSE);
  234.    }
  235. DWORD          iIntervalMSecs ;
  236. void static OnAlertOptionDlgInit (HWND hDlg, PALERT pAlert)
  237.    {
  238.    BOOL           EnableFlag ;
  239.    iIntervalMSecs = pAlert->iIntervalMSecs ;
  240.    
  241.    LocalManualRefresh = pAlert->bManualRefresh ;
  242.    
  243.    if (PlayingBackLog())
  244.       {
  245.       // When playingback log, disable all controls except 
  246.       // the alert interval
  247.       //
  248.       EnableFlag = TRUE ;
  249.       DialogEnable (hDlg, IDD_ALERTOPTIONSMANUALREFRESH, FALSE) ;
  250.       DialogEnable (hDlg, IDD_ALERTOPTIONSPOPUP, FALSE) ;
  251.       DialogEnable (hDlg, IDD_ALERTOPTIONSNETWORKALERT, FALSE) ;
  252.       DialogEnable (hDlg, IDD_ALERTOPTIONSNETGROUPTEXT, FALSE) ;
  253.       DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAME, FALSE) ;
  254.       DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAMETEXT, FALSE) ;
  255.       }
  256.    else
  257.       {
  258.       EnableFlag = !LocalManualRefresh ;
  259.       DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAME, pAlert->bNetworkAlert) ;
  260.       DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAMETEXT, pAlert->bNetworkAlert) ;
  261.       }
  262.    // setup the Update time interval group items
  263.    DialogSetInterval (hDlg, IDD_ALERTOPTIONSINTERVAL, iIntervalMSecs) ;
  264.    DialogEnable (hDlg, IDD_ALERTOPTIONSINTERVAL, EnableFlag) ;
  265.    DialogEnable (hDlg, IDD_ALERTOPTIONSINTERVALTEXT, EnableFlag) ;
  266.    CheckRadioButton(hDlg, IDD_ALERTOPTIONSMANUALREFRESH,
  267.       IDD_ALERTOPTIONSPERIODIC,
  268.       !EnableFlag ? IDD_ALERTOPTIONSMANUALREFRESH : IDD_ALERTOPTIONSPERIODIC) ;
  269.    CheckDlgButton (hDlg, IDD_ALERTOPTIONSEVENTLOG, pAlert->bEventLog) ;
  270.    CheckDlgButton (hDlg, IDD_ALERTOPTIONSPOPUP, pAlert->bSwitchToAlert) ;
  271.    CheckDlgButton (hDlg, IDD_ALERTOPTIONSNETWORKALERT, pAlert->bNetworkAlert) ;
  272.    if (pAlert->MessageName[0])
  273.       {
  274.       DialogSetString (hDlg, IDD_ALERTOPTIONSMSGNAME, pAlert->MessageName) ;
  275.       }
  276.          
  277.    EditSetLimit (GetDlgItem(hDlg, IDD_ALERTOPTIONSMSGNAME),
  278.       sizeof(pAlert->MessageName)/sizeof(TCHAR) - 1) ;
  279.    dwCurrentDlgID = HC_PM_idDlgOptionAlert ;
  280.    WindowCenter (hDlg) ;
  281.    }  // OnAlertOptionDlgInit
  282. BOOL FAR PASCAL AlertOptionDlg (HWND hDlg, WORD msg, 
  283.                                 DWORD wParam, LONG lParam)
  284.    {
  285.    PALERT         pAlert ;
  286.    switch(msg)
  287.       {
  288.       case WM_INITDIALOG:
  289.          pAlert = (PALERT) lParam ;
  290.          OnAlertOptionDlgInit (hDlg, pAlert) ;
  291.          return(TRUE);
  292.     case WM_COMMAND:
  293.          switch(LOWORD(wParam))
  294.             {
  295.             case IDOK:
  296.                {
  297.                FLOAT eTimeInterval ;
  298.                pAlert = AlertData (hWndAlert) ;
  299.                eTimeInterval = DialogFloat (hDlg, IDD_ALERTOPTIONSINTERVAL, NULL) ;
  300.                if (eTimeInterval > MAX_INTERVALSEC ||
  301.                    eTimeInterval < MIN_INTERVALSEC)
  302.                   {
  303.                   DlgErrorBox (hDlg, ERR_BADTIMEINTERVAL) ;
  304.                   SetFocus (DialogControl (hDlg, IDD_ALERTOPTIONSINTERVAL)) ;
  305.                   EditSetTextEndPos (hDlg, IDD_ALERTOPTIONSINTERVAL) ;
  306.                   return (FALSE) ;
  307.                   break ;
  308.                   }
  309.                eTimeInterval = eTimeInterval * (FLOAT) 1000.0 +
  310.                    (FLOAT) 0.5 ;
  311.                iIntervalMSecs = (DWORD) eTimeInterval ;
  312.                pAlert->bNetworkAlert =
  313.                   IsDlgButtonChecked (hDlg, IDD_ALERTOPTIONSNETWORKALERT) ;
  314.                pAlert->bSwitchToAlert =
  315.                   IsDlgButtonChecked (hDlg, IDD_ALERTOPTIONSPOPUP) ;
  316.                pAlert->bEventLog =
  317.                   IsDlgButtonChecked (hDlg, IDD_ALERTOPTIONSEVENTLOG) ;
  318.                if (!PlayingBackLog())
  319.                   {
  320.                   DialogText (hDlg,
  321.                      IDD_ALERTOPTIONSMSGNAME,
  322.                      pAlert->MessageName) ;
  323.                   }
  324.                dwCurrentDlgID = 0 ;
  325.                EndDialog (hDlg, 1) ;
  326.                }
  327.                break ;
  328.             case IDCANCEL:
  329.                dwCurrentDlgID = 0 ;
  330.                EndDialog(hDlg,0);
  331.                return(TRUE);
  332.             
  333.             case IDD_ALERTOPTIONSPERIODIC:
  334.             case IDD_ALERTOPTIONSMANUALREFRESH:
  335.                if (!PlayingBackLog())
  336.                   {
  337.                   // check if the Manual refresh is currently checked.
  338.                   // Then toggle the ManualRefresh button
  339.                   LocalManualRefresh =
  340.                      (LOWORD(wParam) == IDD_ALERTOPTIONSMANUALREFRESH) ;
  341.                   CheckRadioButton(hDlg,
  342.                      IDD_ALERTOPTIONSMANUALREFRESH,
  343.                      IDD_ALERTOPTIONSPERIODIC,
  344.                      LocalManualRefresh ? IDD_ALERTOPTIONSMANUALREFRESH :
  345.                      IDD_ALERTOPTIONSPERIODIC) ;
  346.                      DialogEnable (hDlg,
  347.                         IDD_ALERTOPTIONSINTERVAL,
  348.                         !LocalManualRefresh) ;
  349.                      DialogEnable (hDlg,
  350.                         IDD_ALERTOPTIONSINTERVALTEXT,
  351.                         !LocalManualRefresh) ;
  352.                   }
  353.                break ;
  354. #if 0
  355.             case IDD_ALERTOPTIONSPOPUP:
  356.                bSwitchToAlert = !bSwitchToAlert ;
  357.                CheckDlgButton (hDlg, IDD_ALERTOPTIONSPOPUP, bSwitchToAlert) ;
  358.                break;
  359. #endif
  360.             case IDD_ALERTOPTIONSNETWORKALERT:
  361.                {
  362.                BOOL  bNetworkAlert ;
  363.                bNetworkAlert =
  364.                   IsDlgButtonChecked (hDlg, IDD_ALERTOPTIONSNETWORKALERT) ;
  365.                DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAME, bNetworkAlert) ;
  366.                DialogEnable (hDlg, IDD_ALERTOPTIONSMSGNAMETEXT, bNetworkAlert) ;
  367.                if (bNetworkAlert)
  368.                   {
  369.                   SetFocus (GetDlgItem(hDlg, IDD_ALERTOPTIONSMSGNAME)) ;
  370.                   SendDlgItemMessage(hDlg, IDD_ALERTOPTIONSMSGNAME,
  371.                      EM_SETSEL, 0, 16) ;
  372.                   }
  373.                }
  374.                break;
  375.             case IDD_DISPLAYHELP:
  376.                CallWinHelp (dwCurrentDlgID) ;
  377.                break ;
  378.             default:
  379.                break;
  380.             }
  381.          break;
  382.    default:
  383.       break;
  384.       }
  385.    return (FALSE);
  386.    }  // AlertOptionDlg
  387. BOOL DisplayAlertOptions (HWND hWndParent,
  388.                            HWND hWndAlert)
  389.    {  // DisplayAlertOptions
  390.    PALERT        pAlert ;
  391.    pAlert = AlertData (hWndParent) ;
  392.    if (DialogBoxParam (hInstance, idDlgAlertOptions, 
  393.                        hWndParent, (DLGPROC) AlertOptionDlg, 
  394.                        (LPARAM) pAlert))
  395.       {  // if
  396.       
  397.       if (pAlert->bNetworkAlert && pAlert->hNetAlertThread == 0)
  398.          {
  399.          AlertCreateThread (pAlert) ;
  400.          }
  401.       if (PlayingBackLog())
  402.          {
  403.          if (pAlert->iIntervalMSecs != iIntervalMSecs)
  404.             {
  405.             // a new time interval, re-do the backing back log
  406.             // using the new value...
  407.             pAlert->iIntervalMSecs = iIntervalMSecs ;
  408.             DialogSetInterval (hWndAlert, IDD_ALERTINTERVAL, iIntervalMSecs) ;
  409.             if (pAlert->pLineFirst)
  410.                {
  411.                PlaybackAlert (hWndAlert, 0) ;
  412.                WindowInvalidate (hWndAlert) ;
  413.                }
  414.             }
  415.          }
  416.       else if (LocalManualRefresh != pAlert->bManualRefresh)
  417.          {
  418.          if (!LocalManualRefresh)
  419.             {
  420.             pAlert->iIntervalMSecs = iIntervalMSecs ;
  421.             DialogSetInterval (hWndAlert, IDD_ALERTINTERVAL, iIntervalMSecs) ;
  422.             }
  423.          ToggleAlertRefresh (hWndAlert) ;
  424.          }
  425.       else if (!LocalManualRefresh)
  426.          {
  427.          pAlert->iIntervalMSecs = iIntervalMSecs ;
  428.          SetAlertTimer (pAlert) ;
  429.          DialogSetInterval (hWndAlert, IDD_ALERTINTERVAL, iIntervalMSecs) ;
  430.          }
  431.       }  // if
  432.    return (TRUE) ;
  433.    }  // DisplayAlertOptions