home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / graphics.zip / GTEST2.C < prev    next >
Text File  |  1993-10-04  |  4KB  |  160 lines

  1. #define  INCL_DOS
  2. #define  INCL_WIN
  3. #define  INCL_GPI
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <time.h>
  7. #include <os2.h>
  8. #include <graphics.h>
  9. #include "gtest2.h"
  10.  
  11. /*
  12. ** Local defines
  13. */
  14. #define FLOAT_ARRAY_SIZE 100
  15.  
  16. /*
  17. ** Local Function Prototypes
  18. */
  19. static HGRAPH   hGraph;
  20. void InitTest(HGRAPH hGraph);
  21. MRESULT EXPENTRY TestDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  22.  
  23. /*
  24. ** Global variables
  25. */
  26. static HWND hwndMenu = (HWND)0;
  27.  
  28. /*
  29. ** Main Program
  30. */
  31.  
  32. int main(int argc, char **argv)
  33. {
  34.    HAB      hab;
  35.    HMQ      hmq;
  36.    QMSG     qmsg;
  37.    HWND     hwndFrame;
  38.  
  39.    /* Initialize into PM Session */
  40.    if(!(hab = WinInitialize(0))) {
  41.       DosBeep(1200, 1000);
  42.       return(-1);
  43.    } /* endif */
  44.  
  45.    /* Create a message queue */
  46.    if(!(hmq = WinCreateMsgQueue(hab, 50)))  {
  47.       DosBeep(1200, 1000);
  48.       WinTerminate(hab);
  49.       return(-1);
  50.    } /* endif */
  51.  
  52.    /* Register the SVP Notebook window Class */
  53.    GraphRegister("MYCLASS");
  54.  
  55.    /* Create the test window */
  56.    hwndFrame = WinLoadDlg( HWND_DESKTOP,
  57.                            HWND_DESKTOP,
  58.                            TestDlgProc,
  59.                            (HMODULE)0,
  60.                            ID_TEST2,
  61.                            (PVOID)0);
  62.  
  63.    /* Find the graph handle */
  64.    if(GraphQueryHandle(WinWindowFromID(hwndFrame, ID_GRAPH), &hGraph))
  65.       InitTest(hGraph);
  66.  
  67.    /* Get/Dispatch Message loop */
  68.    while(WinGetMsg(hab, &qmsg, (HWND)0, 0, 0)) {
  69.       WinDispatchMsg(hab, &qmsg);
  70.    } /* endwhile */
  71.  
  72.    /* Destroy the message queue */
  73.    WinDestroyMsgQueue(hmq);
  74.  
  75.    /* Terminate the PM Session */
  76.    WinTerminate(hab);
  77.  
  78.    return(0);
  79. }
  80.  
  81. void InitTest(HGRAPH hGraph)
  82.  
  83. {
  84.    RECTL    rectl;
  85.  
  86.    int   i;
  87.    LONG  lXValue, lYValue;
  88.    float afXData[FLOAT_ARRAY_SIZE], afYData[FLOAT_ARRAY_SIZE];
  89.  
  90.    /* Set the size of the plot */
  91.    GraphPositionPlot(hGraph, 10, 15, 15, 5);
  92.  
  93.    /* Set the title of the graph */
  94.    GraphSetRegionText(hGraph,
  95.                       GRAPH_TITLE,
  96.                       "Test Program");
  97.  
  98.    /* Set the title of the left margin */
  99.    GraphSetRegionText(hGraph,
  100.                       GRAPH_Y_TITLE,
  101.                       "Y-Axis (Units)");
  102.  
  103.    /* Set the title of the footing */
  104.    GraphSetRegionText(hGraph,
  105.                       GRAPH_X_TITLE,
  106.                      "X-Axis (Units)");
  107.  
  108.     /* Set the group count */
  109.    GraphSetGroupCount(hGraph, 1);
  110.  
  111.    /* Set the y-axis options */
  112.    GraphSetYOptions(hGraph, GRAPH_AUTO_LOWERLIMIT, FALSE);
  113.    GraphSetYDataRange(hGraph, 75, 0);  /* Upper limit does not matter */
  114.  
  115.    /* Setup the data */
  116.    GraphSetupData(hGraph,
  117.                   1,
  118.                   GRAPH_DATA_FLOAT,
  119.                   GRAPH_DATA_FLOAT,
  120.                   FLOAT_ARRAY_SIZE);
  121.  
  122.    return;
  123. }
  124.  
  125.  
  126. MRESULT EXPENTRY TestDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  127.  
  128. {
  129.    static int nTimer = 1;
  130.  
  131.    switch (msg) {
  132.    case WM_INITDLG:
  133.       srand((unsigned)time((time_t)0));
  134.       WinStartTimer( WinQueryAnchorBlock(HWND_DESKTOP),
  135.                      hwnd,
  136.                      1,
  137.                      1000);
  138.       break;
  139.    case WM_COMMAND:
  140.       if(SHORT1FROMMP(mp1) == DID_OK) {
  141.          WinPostMsg(hwnd, WM_QUIT, MPFROMLONG(0), MPFROMLONG(0));
  142.          return(0);
  143.       } /* endif */
  144.       break;
  145.    case WM_TIMER: {
  146.       int    i;
  147.       LONG   lMin, lMax;
  148.       float  rX, rY;
  149.       rX = (float)(nTimer * 10);
  150.       rY = 60.0 + (10.0 * log(rX));
  151.       GraphAppendData(hGraph, 1, &rX, &rY);
  152.       nTimer++;
  153.       break;
  154.    } /* endcase */
  155.    } /* endswitch */
  156.  
  157.   return (WinDefDlgProc(hwnd, msg, mp1, mp2));
  158. }
  159.  
  160.