home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBGraph / GraphDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  4.9 KB  |  156 lines

  1. /**********************************************************
  2.  
  3. GraphDlg.cpp 
  4. Copyright TransEra Corporation 1999.
  5.  
  6. ***********************************************************/
  7. #include "stdafx.h"
  8. #include "HTBgraph.h"
  9. #include "GraphDlg.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. #define TIMERVAL            100
  18. #define INITIAL_SIZE_WIDTH    210
  19. #define INITIAL_SIZE_HEIGHT 270
  20. #define COLOR_MAX            255
  21. #define COLOR_MIN            0
  22. #define BOX_PERIMETER        200
  23. #define TEXT_BOX_BOUNDS        240
  24. #define ORIGIN                0
  25. #define BASE_LINE            210
  26. #define GRAPH_ONE            1
  27. #define GRAPH_TWO            2
  28. #define GRAPH_THREE            3
  29. #define SCALE                60
  30. #define BAR_GRAPH_WIDTH        10
  31. #define GRAPH_BASE_START    20
  32.  
  33. GraphDlg::GraphDlg(CWnd* pParent /*=NULL*/)
  34.     : CDialog(GraphDlg::IDD, pParent) 
  35. {
  36.     //{{AFX_DATA_INIT(GraphDlg)
  37.         // NOTE: the ClassWizard will add member initialization here
  38.     //}}AFX_DATA_INIT
  39. }
  40.  
  41.  
  42. void GraphDlg::DoDataExchange(CDataExchange* pDX) 
  43. {
  44.     CDialog::DoDataExchange(pDX);
  45.     //{{AFX_DATA_MAP(GraphDlg)
  46.         // NOTE: the ClassWizard will add DDX and DDV calls here
  47.     //}}AFX_DATA_MAP
  48. }
  49.  
  50.  
  51. BEGIN_MESSAGE_MAP(GraphDlg, CDialog)
  52.     //{{AFX_MSG_MAP(GraphDlg)
  53.     ON_WM_PAINT()
  54.     ON_WM_TIMER()
  55.     //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. /*
  60.     Function:        GraphDlg::OnInitDialog
  61.  
  62.     Description:    Starts Timer and initializes Dialog Box.
  63.  
  64.     Return type:    BOOL 
  65.  
  66.     Notes:            This funtion will initialize the Dialog Window,
  67.                     Set it's starting positions and other Dialog
  68.                     options, this function will also start the timer.        
  69. */
  70. BOOL GraphDlg::OnInitDialog()  
  71. {    
  72.     CDialog::OnInitDialog();    
  73.     SetWindowPos(FromHandle(m_hWnd), g_XPos, g_YPos, 
  74.                 INITIAL_SIZE_WIDTH, INITIAL_SIZE_HEIGHT, SWP_NOZORDER);
  75.     SetTimer(1,TIMERVAL,NULL);        
  76.     return TRUE;  
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. /*
  81.     Function:        GraphDlg::OnPaint
  82.  
  83.     Description:    Draws lines, boxes, colors.
  84.  
  85.     Return type:    void 
  86.  
  87.     Notes:            This function will do the actual "drawing" on the
  88.                     dialog box through the use of a CPaintDC 
  89.                     structure.  The pointers coming into this function 
  90.                     represent data coming from HTBasic and is thus
  91.                     graphically displayed.        
  92. */
  93. void GraphDlg::OnPaint()  
  94. {
  95.     static int iGraphDataInput0, iGraphDataInput1, iGraphDataInput2;    // Integer containing bar height
  96.     CString sOutPutString0, sOutPutString1, sOutPutString2;                // Strings containing text of height 
  97.  
  98.     CPaintDC dc(this); 
  99.     CBrush brush0 (RGB(COLOR_MAX, COLOR_MIN, COLOR_MIN));                // Red Brush Definition
  100.     CBrush brush1 (RGB(COLOR_MIN, COLOR_MAX, COLOR_MIN));                // Green Brush Definition
  101.     CBrush brush2 (RGB(COLOR_MIN, COLOR_MIN, COLOR_MAX));                // Blue Brush Definition
  102.     
  103.     iGraphDataInput0 = (*pBasicVar0);                                    // Generate some Y values
  104.     iGraphDataInput1 = (*pBasicVar1);
  105.     iGraphDataInput2 = (*pBasicVar2);    
  106.     
  107.     //  Draw the box around the bar graphs
  108.     dc.MoveTo(ORIGIN,ORIGIN);
  109.     dc.LineTo(BOX_PERIMETER, ORIGIN);
  110.     dc.LineTo(BOX_PERIMETER, BOX_PERIMETER);
  111.     dc.LineTo(ORIGIN, BOX_PERIMETER);
  112.     dc.LineTo(ORIGIN,ORIGIN);
  113.     //  Draw box around box containing text
  114.     dc.MoveTo(BOX_PERIMETER,BOX_PERIMETER);
  115.     dc.LineTo(BOX_PERIMETER,TEXT_BOX_BOUNDS);
  116.     dc.LineTo(ORIGIN, TEXT_BOX_BOUNDS);
  117.     dc.LineTo(ORIGIN, BOX_PERIMETER);
  118.     dc.SelectObject(&brush0);                                                    // Assign Red Color
  119.     // draw bar graphs
  120.     dc.Rectangle(GRAPH_BASE_START, (BOX_PERIMETER - iGraphDataInput0), 
  121.                 (SCALE * GRAPH_ONE), BOX_PERIMETER);                            // Draw Red Graph
  122.     sOutPutString0.Format("%d", iGraphDataInput0);
  123.     dc.TextOut((GRAPH_BASE_START + BAR_GRAPH_WIDTH), BASE_LINE, sOutPutString0);            
  124.     dc.SelectObject(&brush1);                                                    // Assign Green Color
  125.     dc.Rectangle((GRAPH_BASE_START +SCALE), (BOX_PERIMETER - iGraphDataInput1), 
  126.                 (SCALE * GRAPH_TWO), BOX_PERIMETER);                            // Draw Green Graph
  127.     sOutPutString1.Format("%d", iGraphDataInput1);
  128.     dc.TextOut((GRAPH_BASE_START + SCALE + BAR_GRAPH_WIDTH), BASE_LINE, sOutPutString1);
  129.     dc.SelectObject(&brush2);                                                    // Assign Blue Color
  130.     dc.Rectangle(((GRAPH_TWO * SCALE) + GRAPH_BASE_START), (BOX_PERIMETER - iGraphDataInput2), 
  131.                 (SCALE * GRAPH_THREE), BOX_PERIMETER);                            // Draw Blue Graph
  132.     sOutPutString2.Format("%d", iGraphDataInput2);
  133.     dc.TextOut(((GRAPH_TWO * SCALE) + GRAPH_BASE_START + BAR_GRAPH_WIDTH), 
  134.                 BASE_LINE, sOutPutString2);
  135. }
  136.  
  137. /////////////////////////////////////////////////////////////////////////////
  138. /*
  139.     Function:        GraphDlg::OnTimer
  140.  
  141.     Description:    Strobes Timer for update with invalidate function.    
  142.  
  143.     Return type:    void 
  144.     Argument:        UINT nIDEvent
  145.  
  146.     Notes:            This function simply invalidates the dialog box,
  147.                     this causes it to be updated every time it is
  148.                     invalidated, this is what "creates" the animation
  149.                     or motion effects.        
  150. */
  151. void GraphDlg::OnTimer(UINT nIDEvent)  
  152. {
  153.     Invalidate();
  154.     CDialog::OnTimer(nIDEvent);
  155. }
  156.