C Example Program


//**************************************************************

//

// Description: C example building one graph with the

//	Real-Time Graphics Tools for Windows

//

//*************************************************************

#include <windows.h>
#include <stdlib.h>
#include <math.h>
#include "qcwin.h"
#include "qcwrt.h"
#include "menus.h"

int  idTimer;

HINSTANCE   hInst; 	

HANDLE      hScroll;	

HANDLE      hData; 

PGRAPH_DEF pDynGrDesc = NULL;	

char szAppName[] = "Demo";  

// Prototypes of forward referenced functions

LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM 

	wParam, LPARAM lParam);

BOOL InitApplication(HINSTANCE);

BOOL InitInstance(HINSTANCE, int);

void FAR StartGraphs1 (PPAGE_DEF pPageDesc);  

void FAR DrawP1G1 (PGRAPH_DEF pGrDesc, HDC hdc);

BOOL CALLBACK AboutProc (HWND hDlg, UINT message, WPARAM wParam,

	  LPARAM lParam);

void CALLBACK _export TimerRoutine (HWND hwnd, UINT msg, UINT 

	idTimer, DWORD dwTime);

/************************************************

FUNCTION: WinMain (HINSTANCE, HINSTANCE, LPSTR, int)

  PURPOSE: calls initialization function, processes message loop

********************************************************/

int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

			LPSTR lpCmdLine, int nCmdShow)

{

 MSG msg;

 if (!hPrevInstance)

	 if (!InitApplication(hInstance))

	  return (FALSE);

 if (!InitInstance(hInstance, nCmdShow))

	 return (FALSE);

 // Message loop

 while (GetMessage(&msg, NULL, NULL, NULL))

 {

	 TranslateMessage(&msg);

	 DispatchMessage(&msg);

 };

 return (msg.wParam);

}

/*******************************************************

  FUNCTION: InitApplication (HINSTANCE)

  PURPOSE: Initializes window data and registers window classes

********************************************************/

BOOL InitApplication (HINSTANCE hInstance)

{

	 WNDCLASS  wc;

	 // main window class

	 wc.style = CS_HREDRAW | CS_VREDRAW;

	 wc.lpfnWndProc = MainWndProc;

	 wc.cbClsExtra = 0;

	 wc.cbWndExtra = 0;

	 wc.hInstance = hInstance;

	 wc.hIcon = LoadIcon(hInstance, "LOGO");

	 wc.hCursor = LoadCursor(NULL, IDC_ARROW);

	 wc.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH);

	 wc.lpszMenuName = NULL;

	 wc.lpszClassName = szAppName;

	 return (RegisterClass(&wc));

}

/*******************************************************

  FUNCTION: InitInstance(HINSTANCE, int)

  PURPOSE:  Saves instance handle and creates main window

********************************************************/

BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)

{

	HWND   hwnd;

	 // save current instance - MUST BE HERE

	hInst = hInstance;

	hwnd = CreateWindow

	(

		szAppName,           // Create main window

		"Strip Chart Emulation",  // Main window title

		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,

		NULL,

		NULL,

		hInstance,

		NULL

	);

	if (!hwnd)

	return (FALSE);

	ShowWindow(hwnd, nCmdShow);

	UpdateWindow(hwnd);

	return (TRUE);

}

/*************************************************************************

	 Main window procedure

**************************************************************************/

LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, 

			WPARAM wParam,	LPARAM lParam)

{

  static PPAGE_DEF pPageDesc1 = NULL;

  HWND hwndPage;

  switch (message)

  {

	case WM_CREATE:

		pPageDesc1 = WGCreatePage("PAGE1", // page ID string

		 	hwnd,               // handle to the parent window

		 	hInst,              // application instance handle

		 	"Simulator",        // Window title string

		 	StartGraphs1,       // pointer to graph creation function

		 	NULL,               // no menu

		 	C_LIGHTGRAY,        // window background color

		 	MM_ISOTR,           // window sizing mode

		 	0L, // window style

		 	PAGE_FULL,

		 	0, 0, 0, 0);   // initial window size and position

					 	// if used (not used here)


		idTimer = SetTimer (NULL, 0, 250, 

			(TIMERPROC)TimerRoutine);  // start timer

			return 0;


	case WM_DESTROY:

		KillTimer (NULL, idTimer);	// stop the timer

		WRCleanup(TRUE);	// clean up real-time tools memory

					// and free data arrays

		PostQuitMessage(0);

		return 0;

	}

  return (DefWindowProc(hwnd, message, wParam, lParam));

}

/****************************************************************

	Routine StartGraphs1 is called by the Quinn-Curtis

	Windows Charting Tools when a page is created.

	It must be filled by the user, normally with

	functions WGCreateGraph that initialize individual graphs.

***********************************************************************/

void FAR StartGraphs1(PPAGE_DEF pPageDesc)

{

  // Initialize graphs

  pDynGrDesc = WGCreateGraph (pPageDesc,

	DrawP1G1, 		// function which builds graph

	0.005, 0.005 		// window relative position 

	0.49, 0.8, 		// inside parent page window

	C_LIGHTGRAY, 		// light gray background

	C_WHITE, 		// white border

	1); 			// border width in pixels

	

}

/*******************************************************

	Builds the graph using Q-C Real-Time Graphics Calls

*******************************************************/

void FAR DrawP1G1 (PGRAPH_DEF pGrDesc, HDC hdc)

{

   HANDLE   hAxisX, hAxisY;  // axes handles

	BOOL     bFlags [NALMLINES];

	short    nTraces = 3;

	short    nLineColor [DYN_MAXVAL];

	short    nLineWidth [DYN_MAXVAL];

	short	 i, nGridUpdate = 4;

	realtype rSampleInt, rResetInt;

	realtype rHigh, rLow, rSetp;

	// define the plotting area of the graph

	WGSetPlotArea(pGrDesc, hdc, 0.24, 0.15, 0.95, 0.57, C_BLACK);

	// scale the plotting area for an x range of 0 to 1.0

	// and y range of -2.0 to 2.0

	WGScalePlotArea (pGrDesc, 0.0, -2.0, 1.0, 2.0);

	// set the intercepts to 0.0, -2.0

	WGSetXYIntercepts (pGrDesc, 0.0, -2.0);

	// axes to be drawn in solid, black, 1 pixels thick

	WGSetLineStyle(pGrDesc, hdc, PS_SOLID, 1, C_CYAN);

	// set current font to Arial, 8 points

	WGSetTextByName (C_RED, "Arial", 8, 0);

	// draw the x axis

	hAxisX = WGDrawXAxis(pGrDesc, hdc, 0.2, 0, POS_MIDDLE);

	// draw the y axis 

	hAxisY = WGDrawYAxis(pGrDesc, hdc, 1.0, 1, POS_LEFT);

	// Label the x axis

	WGLabelAxis(pGrDesc, hdc, hAxisX, POS_BELOW, NF_DECIMAL, 1, 

			LL_ON, NULL);

	WGSetTextByName (C_RED, "Arial", 8, TEXT_ITAL);

	// Label the y axis

	WGLabelAxis(pGrDesc, hdc, hAxisY, POS_LEFT, NF_DECIMAL, 1, 

			LL_ON, NULL);

	// Set the line style for the dynamic grids

	WGSetLineStyle(pGrDesc, hdc, PS_DOT, 1, C_LIGHTCYAN);

	// set current font to Arial, 8 points

	WGSetTextByName (C_RED, "Arial", 8, TEXT_BOLD);

	// Write axes titles

	WGTitleAxis(pGrDesc, hdc, hAxisX, POS_BELOW, "Minutes");

	WGTextNorm (pGrDesc, hdc, "Volts", 0.1, 0.35,

			TA_CENTER | TA_BOTTOM, TEXT_VERTLEFT);

	// set current font

	WGSetTextByName (C_GREEN, "Arial", 10, TEXT_BOLD | TEXT_ITAL);

	// Write graph title

	WGTitleGraph(pGrDesc, hdc, "Horizontal Strip Chart");

	//******************************************************

	// SET UP DYNAMIC PORTION OF GRAPH

	// Display a dynamic grid x and y axes

	WRDynGrid(pGrDesc, hAxisX, GRID_MAJOR, nGridUpdate);

	WRDynGrid(pGrDesc, hAxisY, GRID_MAJOR, nGridUpdate);

	// Assign each line style, width and color for the scroll graph

	for (i = 0; i  1000)

		nCount = 0;

	

	// Update the data set

	WRUpdateData (hData, rNewVals, NULL);

/**************************************************************************/