home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
chart101.zip
/
DEMO.C
< prev
next >
Wrap
Text File
|
1995-06-22
|
12KB
|
267 lines
/****************************************************************************/
/* */
/* This is a business graphics sample demonstration program. This program */
/* was created and distributed by The Crossley Group Inc. The program */
/* may be changed or modified as so specified in the software license */
/* agreement which accompanied the Developer's Business Graphics Toolkit. */
/* */
/* ------------------------------------------------------------------------ */
/* */
/* External values unique to this program are stored in the RES.H file. */
/* */
/****************************************************************************/
#define GPIPRIMITIVES
#define INCL_GPI
#define INCL_WIN
#define INCL_DOSNLS
#include <os2.h> /* PM header file */
#include <stdio.h> /* PM header file */
#include <string.h> /* C/2 string functions */
#include <stdlib.h> /* */
#define CHART_OS2_32
#include <CHART.H> /* Business graphics identifiers */
#include "RES.H" /* Resource symbolic identifiers */
/****************************************************************************/
/* Chart Data */
/****************************************************************************/
PCH aszLegends[3] = { "John Doe", "Jane Doe", "Frank Doe" } ;
static CHARTPOINTER pxx;
#define FLOAT float
typedef FLOAT FAR *PFLOAT;
static FLOAT ausData1[] = { (FLOAT)50.0, (FLOAT)10.0, (FLOAT)30.0,(FLOAT)70.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0};
static FLOAT ausData2[] = { (FLOAT)90.0, (FLOAT)40.0, (FLOAT)10.0,(FLOAT)60.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0};
static FLOAT ausData3[] = { (FLOAT)50.0, (FLOAT)10.0, (FLOAT)30.0,(FLOAT)70.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0,
(FLOAT)00.0, (FLOAT)00.0, (FLOAT)00.0,(FLOAT)00.0, (FLOAT)00.0};
static PFLOAT apDatap[3] = { ausData1, ausData2,ausData3 };
PCH str[4] = {"String 1","String 2","String 3","String 4"};
static CHARTHIGHLIGHT hl;
/****************************************************************************/
/* Function Prototypes */
/****************************************************************************/
MRESULT EXPENTRY MyWindowProc(HWND ,ULONG ,MPARAM ,MPARAM );
/**************************************************************************/
/* Static allocation */
/**************************************************************************/
static HAB hab; /* PM anchor block handle */
static ULONG flChartFlags; /* Chart creation flags */
static HWND hChart; /* Chart window handle */
static HWND hwndFrame; /* Frame window handle */
static HWND hwndClient; /* Client area window handle */
static USHORT usErrors; /* Business graphics errors */
static RECTL ClientRctl; /* Size of client window */
/****************************************************************************/
/********************** Start of main procedure ***************************/
/****************************************************************************/
int main(void)
{
HMQ hmq; /* Message queue handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags */
HWND hwndGraphClient; /* Client area window handle */
hab = WinInitialize(0L); /* Initialize PM */
hmq = WinCreateMsgQueue(hab, 0); /* Create a message queue */
WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
"PrWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class Style */
0 /* No extra window words */
);
flCreate = FCF_TITLEBAR|FCF_MENU|FCF_SIZEBORDER|FCF_MINMAX|FCF_SYSMENU|
FCF_TASKLIST|FCF_ICON|FCF_SHELLPOSITION|FCF_ACCELTABLE;
hwndFrame = WinCreateStdWindow(HWND_DESKTOP, /* Desktop window is parent */
WS_VISIBLE, /* No frame styles */
(PULONG)&flCreate, /* Frame control flag */
"PrWindow", /* Client window class name */
"", /* No window text */
0L, /* No special class style */
0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
(PHWND)&hwndClient /* Client window handle */
);
/****************************************************************************/
/* Get and dispatch messages from the application message queue */
/* until WinGetMsg returns FALSE, indicating a WM_QUIT message. */
/****************************************************************************/
while (WinGetMsg(hab, (PQMSG)&qmsg, (HWND)NULL, 0, 0))
WinDispatchMsg(hab, (PQMSG)&qmsg);
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue(hmq); /* and */
WinTerminate(hab); /* terminate the application */
}
/****************************************************************************/
/********************** Start of window procedure ***************************/
/****************************************************************************/
MRESULT EXPENTRY MyWindowProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
{
HPS hps; /* Presentation Space handle */
USHORT usCommand; /* WM_COMMAND command value */
SHORT i; /* Utility counter */
POINTL px;
USHORT count;
char legendx[50];
float dx[10];
BOOL ans;
SHORT x,y;
static USHORT point = 5;
switch (msg) {
case WM_COMMAND : /* Process menu command & accel keys */
usCommand = SHORT1FROMMP(mp1); /* Extract the command value */
switch (usCommand) {
case IDM_EXIT :
WinPostMsg(hwnd, WM_CLOSE, 0L, 0L);
break;
default :
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
break;
case WM_CLOSE :
/*******************************************************************/
/* This is the place to put your termination routines */
/*******************************************************************/
WinPostMsg(hwnd, WM_QUIT, 0L, 0L);/* Cause termination */
break;
case WM_CREATE :
/*******************************************************************/
/* Chart Initialization is performed here. */
/*******************************************************************/
WinQueryWindowRect(hwnd, &ClientRctl);
/****************************************************************/
/* Create the Chart Object */
/****************************************************************/
hChart = ChartCreate(hwnd, /* Client window */
CH_BAR,
CH_X_GRID |CH_CONNECTED| CH_Y_GRID | CH_GRAPHIC_FRAME |CH_TOUCH, /* Flags */
&ClientRctl, /* Client rectangle area */
&usErrors, /* Pointer to error location */
CH_DATA_FLOAT, /* Type of data for chart */
3, /* Number of data groups */
4, /* Number of points */
3); /* Number of dimensions */
/****************************************************************/
/* Provide the chart with some data to chart */
/****************************************************************/
for (i = 0; i < 3; ++i) {
ChartData(hChart, /* Chart handle */
i+1, /* Data group number */
(PUSHORT)apDatap[i], /* Location of data */
4, /* Number of data items to chart */
0, /* Reserved */
CH_DATA_FLOAT, /* Type of data to chart */
aszLegends[i]); /* Legend for the group */
}
ChartTexts(hChart,"Medical Tests", NULL,"Unknown",NULL);
ChartSetLineWidth(hChart,3);
ChartSetXTicksString(hChart,CH_WIDTH,4,(PCH)&str);
/*
hl.point = 2;
hl.flags = CH_HL_PATTERN | CH_HL_PATTERN_COLOR | CH_HL_PATTERN_OVERLAY;
hl.pattern = PATSYM_DIAG1;
hl.pattern_color = CLR_BLACK;
ChartDataHighlight(hChart,1,1,&hl);
ChartSetGroupPattern(hChart,2,PATSYM_DIAG1,FALSE,0L);
ChartSetMaxYValue(hChart,(double)200.0);
*/
break;
case WM_BUTTON1DOWN:
ChartOutputMetaFile(hChart,"test.met");
return WinDefWindowProc(hwnd, msg, mp1, mp2);
break;
case WM_PAINT :
/*******************************************************************/
/* Window contents are drawn here in WM_PAINT processing. */
/*******************************************************************/
WinSetWindowText(hwndFrame,"Application Name");
hps = WinBeginPaint(hwnd, (HPS)0, (PRECTL)0);
WinQueryWindowRect(hwnd, &ClientRctl);
if (ChartSetRect(hChart,&ClientRctl)) {
ChartPaint(hChart,hps); /* Make the chart visible */
}
WinEndPaint(hps);
break;
default :
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
return FALSE;
}