home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / chart101.zip / DEMO.C < prev    next >
Text File  |  1995-06-22  |  12KB  |  267 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*  This is a business graphics sample demonstration program. This program  */
  4. /*  was created and distributed by The Crossley Group Inc. The program      */
  5. /*  may be changed or modified as so specified in the software license      */
  6. /*  agreement which accompanied the Developer's Business Graphics Toolkit.  */
  7. /*                                                                          */
  8. /* ------------------------------------------------------------------------ */
  9. /*                                                                          */
  10. /*  External values unique to this program are stored in the RES.H file.    */
  11. /*                                                                          */
  12. /****************************************************************************/
  13.  
  14. #define GPIPRIMITIVES
  15.  
  16. #define  INCL_GPI
  17.  
  18. #define INCL_WIN
  19. #define INCL_DOSNLS
  20. #include <os2.h>                       /* PM header file                    */
  21. #include <stdio.h>                     /* PM header file                    */
  22. #include <string.h>                    /* C/2 string functions              */
  23. #include <stdlib.h>                    /*                                   */
  24.  
  25. #define CHART_OS2_32
  26. #include <CHART.H>                     /* Business graphics identifiers     */
  27. #include "RES.H"                       /* Resource symbolic identifiers     */
  28.  
  29.  
  30.  
  31.  
  32. /****************************************************************************/
  33. /*                        Chart Data                                        */
  34. /****************************************************************************/
  35.  
  36. PCH        aszLegends[3] =  { "John Doe", "Jane Doe", "Frank Doe" } ;
  37.  
  38.  
  39. static CHARTPOINTER pxx;
  40.  
  41. #define FLOAT float
  42.  
  43. typedef FLOAT FAR *PFLOAT;
  44.  
  45. static FLOAT  ausData1[] =  { (FLOAT)50.0, (FLOAT)10.0, (FLOAT)30.0,(FLOAT)70.0, (FLOAT)00.0,
  46.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
  47.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
  48.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0};
  49.  
  50. static FLOAT  ausData2[] =  { (FLOAT)90.0, (FLOAT)40.0, (FLOAT)10.0,(FLOAT)60.0, (FLOAT)00.0,
  51.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
  52.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
  53.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0};
  54.  
  55. static FLOAT  ausData3[] =  { (FLOAT)50.0, (FLOAT)10.0, (FLOAT)30.0,(FLOAT)70.0, (FLOAT)00.0,
  56.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
  57.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
  58.                               (FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0};
  59.  
  60.  
  61. static PFLOAT apDatap[3] = { ausData1, ausData2,ausData3 };
  62.  
  63. PCH str[4] = {"String 1","String 2","String 3","String 4"};
  64.  
  65. static CHARTHIGHLIGHT hl;
  66.  
  67.  
  68. /****************************************************************************/
  69. /* Function Prototypes                                                      */
  70. /****************************************************************************/
  71.  
  72. MRESULT EXPENTRY MyWindowProc(HWND ,ULONG ,MPARAM ,MPARAM );
  73.  
  74. /**************************************************************************/
  75. /* Static allocation                                                      */
  76. /**************************************************************************/
  77.  
  78. static HAB           hab;              /* PM anchor block handle            */
  79. static ULONG         flChartFlags;     /* Chart creation flags              */
  80. static HWND          hChart;           /* Chart window handle               */
  81. static HWND          hwndFrame;        /* Frame window handle               */
  82. static HWND          hwndClient;       /* Client area window handle         */
  83. static USHORT        usErrors;         /* Business graphics errors          */
  84. static RECTL         ClientRctl;       /* Size of client window             */
  85.  
  86. /****************************************************************************/
  87. /**********************  Start of main procedure  ***************************/
  88. /****************************************************************************/
  89.  
  90. int  main(void)
  91. {
  92.    HMQ           hmq;                  /* Message queue handle              */
  93.    QMSG          qmsg;                 /* Message from message queue        */
  94.    ULONG         flCreate;             /* Window creation control flags     */
  95.    HWND          hwndGraphClient;      /* Client area window handle         */
  96.  
  97.  
  98.    hab = WinInitialize(0L);            /* Initialize PM                     */
  99.    hmq = WinCreateMsgQueue(hab, 0);    /* Create a message queue            */
  100.    WinRegisterClass(                   /* Register window class             */
  101.       hab,                             /* Anchor block handle               */
  102.       "PrWindow",                      /* Window class name                 */
  103.       (PFNWP)MyWindowProc,             /* Address of window procedure       */
  104.       CS_SIZEREDRAW,                   /* Class Style                       */
  105.       0                                /* No extra window words             */
  106.       );
  107.  
  108.    flCreate = FCF_TITLEBAR|FCF_MENU|FCF_SIZEBORDER|FCF_MINMAX|FCF_SYSMENU|
  109.       FCF_TASKLIST|FCF_ICON|FCF_SHELLPOSITION|FCF_ACCELTABLE;
  110.  
  111.    hwndFrame = WinCreateStdWindow(HWND_DESKTOP, /* Desktop window is parent */
  112.       WS_VISIBLE,                      /* No frame styles                   */
  113.       (PULONG)&flCreate,               /* Frame control flag                */
  114.       "PrWindow",                      /* Client window class name          */
  115.       "",                              /* No window text                    */
  116.       0L,                              /* No special class style            */
  117.       0L,                              /* Resource is in .EXE file          */
  118.       ID_WINDOW,                       /* Frame window identifier           */
  119.       (PHWND)&hwndClient               /* Client window handle              */
  120.       );
  121.  
  122.  
  123. /****************************************************************************/
  124. /* Get and dispatch messages from the application message queue             */
  125. /* until WinGetMsg returns FALSE, indicating a WM_QUIT message.             */
  126. /****************************************************************************/
  127.  
  128.    while (WinGetMsg(hab, (PQMSG)&qmsg, (HWND)NULL, 0, 0))
  129.       WinDispatchMsg(hab, (PQMSG)&qmsg);
  130.    WinDestroyWindow(hwndFrame);        /* Tidy up...                        */
  131.    WinDestroyMsgQueue(hmq);            /* and                               */
  132.    WinTerminate(hab);                  /* terminate the application         */
  133. }
  134.  
  135.  
  136.  
  137.  
  138. /****************************************************************************/
  139. /********************** Start of window procedure ***************************/
  140. /****************************************************************************/
  141.  
  142. MRESULT EXPENTRY MyWindowProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  143. {
  144.    HPS           hps;                  /* Presentation Space handle         */
  145.    USHORT        usCommand;            /* WM_COMMAND command value          */
  146.    SHORT         i;                    /* Utility counter                   */
  147.    POINTL        px;
  148.    USHORT        count;
  149.    char          legendx[50];
  150.    float         dx[10];
  151.    BOOL          ans;
  152.    SHORT         x,y;
  153.  
  154. static USHORT point = 5;
  155.  
  156.  
  157.    switch (msg) {
  158.       case  WM_COMMAND :               /* Process menu command & accel keys */
  159.          usCommand = SHORT1FROMMP(mp1); /* Extract the command value        */
  160.  
  161.          switch (usCommand) {
  162.             case  IDM_EXIT :
  163.                WinPostMsg(hwnd, WM_CLOSE, 0L, 0L);
  164.                break;
  165.             default  :
  166.                return  WinDefWindowProc(hwnd, msg, mp1, mp2);
  167.          }
  168.          break;
  169.  
  170.       case  WM_CLOSE :
  171.  
  172.          /*******************************************************************/
  173.          /* This is the place to put your termination routines              */
  174.          /*******************************************************************/
  175.  
  176.          WinPostMsg(hwnd, WM_QUIT, 0L, 0L);/* Cause termination             */
  177.          break;
  178.  
  179.       case WM_CREATE :
  180.  
  181.          /*******************************************************************/
  182.          /* Chart Initialization is performed here.                         */
  183.          /*******************************************************************/
  184.  
  185.          WinQueryWindowRect(hwnd, &ClientRctl);
  186.  
  187.  
  188.             /****************************************************************/
  189.             /* Create the Chart Object                                      */
  190.             /****************************************************************/
  191.  
  192.  
  193.             hChart = ChartCreate(hwnd, /* Client window                     */
  194.                CH_BAR,
  195.                CH_X_GRID |CH_CONNECTED| CH_Y_GRID | CH_GRAPHIC_FRAME |CH_TOUCH, /* Flags */
  196.                &ClientRctl,            /* Client rectangle area             */
  197.                &usErrors,              /* Pointer to error location         */
  198.                CH_DATA_FLOAT,          /* Type of data for chart            */
  199.                3,                      /* Number of data groups             */
  200.                4,                      /* Number of points                  */
  201.                3);                     /* Number of dimensions              */
  202.  
  203.             /****************************************************************/
  204.             /* Provide the chart with some data to chart                    */
  205.             /****************************************************************/
  206.  
  207.             for (i = 0; i < 3; ++i) {
  208.                   ChartData(hChart,    /* Chart handle                      */
  209.                   i+1,                 /* Data group number                 */
  210.                   (PUSHORT)apDatap[i], /* Location of data                  */
  211.                   4,                   /* Number of data items to chart     */
  212.                   0,                   /* Reserved                          */
  213.                   CH_DATA_FLOAT,       /* Type of data to chart             */
  214.                   aszLegends[i]);      /* Legend for the group              */
  215.             }
  216.  
  217.             ChartTexts(hChart,"Medical Tests", NULL,"Unknown",NULL);
  218.  
  219.             ChartSetLineWidth(hChart,3);
  220.  
  221.             ChartSetXTicksString(hChart,CH_WIDTH,4,(PCH)&str);
  222. /*
  223.             hl.point = 2;
  224.             hl.flags = CH_HL_PATTERN | CH_HL_PATTERN_COLOR | CH_HL_PATTERN_OVERLAY;
  225.             hl.pattern = PATSYM_DIAG1;
  226.             hl.pattern_color = CLR_BLACK;
  227.  
  228.             ChartDataHighlight(hChart,1,1,&hl);
  229.  
  230.             ChartSetGroupPattern(hChart,2,PATSYM_DIAG1,FALSE,0L);
  231.   
  232.             ChartSetMaxYValue(hChart,(double)200.0);
  233. */
  234.          break;
  235.       case WM_BUTTON1DOWN:
  236.         ChartOutputMetaFile(hChart,"test.met");
  237.          return  WinDefWindowProc(hwnd, msg, mp1, mp2);
  238.          break;
  239.  
  240.       case WM_PAINT :
  241.  
  242.          /*******************************************************************/
  243.          /* Window contents are drawn here in WM_PAINT processing.          */
  244.          /*******************************************************************/
  245.  
  246.          WinSetWindowText(hwndFrame,"Application Name");
  247.  
  248.          hps = WinBeginPaint(hwnd, (HPS)0, (PRECTL)0);
  249.             WinQueryWindowRect(hwnd, &ClientRctl);
  250.    
  251.             if (ChartSetRect(hChart,&ClientRctl)) {
  252.                ChartPaint(hChart,hps);      /* Make the chart visible            */
  253.             }
  254.          WinEndPaint(hps);
  255.  
  256.  
  257.  
  258.          break;
  259.  
  260.       default  :
  261.          return  WinDefWindowProc(hwnd, msg, mp1, mp2);
  262.    }
  263.    return  FALSE;
  264. }
  265.  
  266.  
  267.