下面是Demo6中的一个画曲线的代码。现在还没有看明白,现在的问题是,里面有几个变量在程序的开始并没有定义,但却可以使用,我很糊涂。还请教!!如: vtDataX.vt = VT_R8;
dDataY ,
vtDataX.u.dblVal
以下是程序代码:
#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
#define NUMVALUES_1 2
#define NUMVALUES_2 95
double X_Values[96] = {
0.0, 1.0, 2.0, 3.0, 4.0,
5.0, 6.0, 7.0, 8.0, 9.0,
10.0, 11.0, 12.0, 13.0, 14.0,
15.0, 16.0, 17.0, 18.0, 19.0,
20.0, 21.0,22.0, 23.0, 24.0,
25.0, 26.0, 27.0, 28.0, 29.0,
30.0, 31.0, 32.0, 33.0, 34.0,
35.0, 36.0, 37.0, 38.0, 39.0,
40.0, 41.0, 42.0, 43.0, 44.0,
45.0, 46.0, 47.0, 48.0, 49.0,
50.0, 51.0, 52.0, 53.0, 54.0,
55.0, 56.0, 57.0, 58.0, 59.0,
60.0, 61.0, 62.0, 63.0, 64.0,
65.0, 66.0, 67.0, 68.0, 69.0,
70.0, 71.0, 72.0, 73.0, 74.0,
75.0, 76.0, 77.0, 78.0, 79.0,
80.0, 81.0, 82.0, 83.0, 84.0,
85.0, 86.0, 87.0, 88.0, 89.0,
90.0, 91.0, 92.0, 93.0, 94.0,
95.0,
};
double Y_Values[96] = {
0.0, 0.1, 0.2, 0.3, 0.7,
1.4, 2.3, 3.0, 4.6, 5.4,
7.0, 9.0, 11.0, 12.0, 14.0,
16.0, 18.0, 20.0,22.0, 24.0,
25.0, 27.0, 28.0, 29.0, 30.0,
30.7, 31.2, 31.5, 32.0, 32.1,
31.9, 31.6, 31.0, 30.6, 30.0,
29.5, 28.7, 27.8, 27.0, 26.0,
25.3, 24.3, 24.0, 23.0, 22.0,
21.6, 20.6, 20.0, 19.5, 19.1,
18.8, 18.5, 18.3, 18.1, 18.0,
17.9, 18.0, 18.2, 18.3, 18.5,
18.9, 19.0, 19.2, 19.5, 20.0,
20.5, 20.8, 21.0, 21.3, 21.8,
22.4, 22.6, 22.9, 23.3, 23.5,
23.6, 23.8, 24.0, 24.2, 24.4,
24.4, 24.4, 24.4, 24.4, 24.3,
24.2, 24.1, 24.0, 23.9, 23.8,
23.6, 23.4, 23.3, 23.1,22.9,
22.8,
};
double X_Values_Step[ 3 ] = {
0.0, 0.0, 95.0,
};
double Y_Values_Step[ 3 ] = {
0.0, 22.2, 22.2,
};
VARIANT vtDataX;
double dDataY;
int i;
double x;
double y;
VariantInit( &vtDataX );
SetOperation(lpszPictureName,lpszObjectName,FALSE); //Bedienung sperren - disable operator control
//FunctionTrendControl parametrieren---set FunctionTrendControl parameters
SetPropBOOL(lpszPictureName,"TrendYX1","CommonY",TRUE);
SetPropBOOL(lpszPictureName,"TrendYX1","CommonX",TRUE);
// Index der Kurve 1 setzen -- Set index for trend 1
SetPropBOOL( lpszPictureName, "TrendYX1", "Index", 0);
//Y-Achse -- Y-axis
SetPropBOOL(lpszPictureName,"TrendYX1","AutorangeY",FALSE);
SetPropDouble(lpszPictureName,"TrendYX1","BeginY",0);
SetPropDouble(lpszPictureName,"TrendYX1","EndY",33);
//X-Achse -- X-axis
SetPropBOOL(lpszPictureName,"TrendYX1","AutorangeX",FALSE);
SetPropDouble(lpszPictureName,"TrendYX1","BeginX",0);
SetPropDouble(lpszPictureName,"TrendYX1","EndX",95);
// Alle Daten der Kurve 1 l?schen -- delete trend 1 data
SetPropBOOL( lpszPictureName, "TrendYX1", "DeleteData", TRUE );
// Index der Kurve 2 setzen -- Set index for trend 2
SetPropBOOL( lpszPictureName, "TrendYX1", "Index", 1);
//Y-Achse -- Y-axis
SetPropBOOL(lpszPictureName,"TrendYX1","AutorangeX",FALSE);
SetPropDouble(lpszPictureName,"TrendYX1","BeginX",0);
SetPropDouble(lpszPictureName,"TrendYX1","EndX",33);
//X-Achse -- X-axis
SetPropBOOL(lpszPictureName,"TrendYX1","AutorangeX",FALSE);
SetPropDouble(lpszPictureName,"TrendYX1","BeginX",0);
SetPropDouble(lpszPictureName,"TrendYX1","EndX",95);
// Alle Daten der Kurve 2 l?schen - delete trend 2 data
SetPropBOOL( lpszPictureName, "TrendYX1", "DeleteData", TRUE );
//Kurve 1 schwarz -- Trend 1 black
SetPropBOOL( lpszPictureName, "TrendYX1", "Index", 0); //Index für Kurve 1 setzen -- Set index for trend 1
for( i =0; i <= NUMVALUES_1; ++i )
{
// Füllen des Wertepaares -- fill data pair with data from x and y value list
vtDataX.vt = VT_R8;
dDataY = Y_Values_Step[i]; // Y-Wert -- Y-value
vtDataX.u.dblVal = (double)X_Values_Step[i]; // X-Wert -- X-value
// X-Wert setzen
PDLRTSetPropEx( PDLRT_AM_DEFAULT, lpszPictureName, "TrendYX1", "DataX",
VT_VARIANT, (void*)&vtDataX, NULL, NULL, 0, NULL, NULL );
//printf("Index %d\r\n",i);
//printf("XValue%f\r\n",vtDataX.u.dblVal);
// Y-Werte setzen -- set Y-values
SetPropDouble( lpszPictureName, "TrendYX1", "DataY", dDataY );
//printf("yValue%f\r\n",dDataY);
// X-/Y- Werte hinten anfügen. -- add X/Y values
SetPropBOOL( lpszPictureName, "TrendYX1", "InsertData", TRUE );
VariantClear( &vtDataX );
}
//Kurve 2 rot -- Trend 2 red
SetPropBOOL( lpszPictureName, "TrendYX1", "Index", 1); //Index für Kurve 2 setzen -- Set index for trend 2
for( i =0; i <= NUMVALUES_2; ++i )
{
// Füllen des Wertepaares -- fill data pair with data from x and y value list
vtDataX.vt = VT_R8;
dDataY = Y_Values[i]; // Y-Wert -- Y-value
vtDataX.u.dblVal = (double)X_Values[i]; // X-Wert -- X-value
// X-Wert setzen
PDLRTSetPropEx( PDLRT_AM_DEFAULT, lpszPictureName, "TrendYX1", "DataX",
VT_VARIANT, (void*)&vtDataX, NULL, NULL, 0, NULL, NULL );
//printf("Index %d\r\n",i);
//printf("XValue%f\r\n",vtDataX.u.dblVal);
// Y-Werte setzen -- set Y-values
SetPropDouble( lpszPictureName, "TrendYX1", "DataY", dDataY );
//printf("yValue%f\r\n",dDataY);
// X-/Y- Werte hinten anfügen. -- add X/Y values
SetPropBOOL( lpszPictureName, "TrendYX1", "InsertData", TRUE );
VariantClear( &vtDataX );
}
SetOperation(lpszPictureName,lpszObjectName,TRUE); //Bedienung freigeben - enable operator control
}