赞
踩
经过一晚上的研究,总算把读取核新数据日K线文件(*.day)的办法搞出来了:
如下:
void OnReadDay(CString DayFileName)
{
FILE *pfDay;
if((pfDay =fopen(DayFileName,"rb"))==NULL)
{
return;
}
int Header;
int Unused;
int DateField;
unsigned int Open,High,Low,ClosePrice,Volume,Money;
int i;
fread(&Header,sizeof(int),1,pfDay); //读取文件头的内容,开始,具体内容不重要
for(i=1;i<16;i++)
fread(&Unused,sizeof(int),1,pfDay); //读取文件头共计64字节,结束
fread(&DateField,sizeof(int),1,pfDay); //读取记录的开始,日期
m_strDate.Format("%d",DateField);
fread(&Open,sizeof(unsigned int),1,pfDay); //开盘价
fread(&High,sizeof(unsigned int),1,pfDay); //最高价
fread(&Low,sizeof(unsigned int),1,pfDay); //最低价
fread(&ClosePrice,sizeof(unsigned int),1,pfDay); //收盘价
fread(&Money,sizeof(int),1,pfDay); //成交金额
fread(&Volume,sizeof(unsigned int),1,pfDay); //成交量
for(i=1;i<6;i++)
fread(&Unused,sizeof(unsigned int),1,pfDay); //无用
///第一笔记录全部读取完毕/
double fOpen,fHigh,fLow,fClose,fVol,fMoney;
//把读取数据转换成为保留两位小数的单价。
ConvertPrice(Open,&fOpen);
ConvertPrice(High,&fHigh);
ConvertPrice(Low,&fLow);
ConvertPrice(ClosePrice,&fClose);
//显示在EDIT控件中
m_strOpen.Format("%.2f元",fOpen);
m_strHigh.Format("%.2f元",fHigh);
m_strLow.Format("%.2f元",fLow);
m_strClose.Format("%.2f元",fClose);
fVol = Volume/100.0; //把成交量换算为手数
fMoney=Money/10000.0; //把成交金额换算为万元
m_strVolume.Format("%.0f手",fVol);
m_strMoney.Format("%.0f万元",fMoney);
UpdateData(false);
}
//-----------------------------------------------------
void OnBtnOnreadday()
{
OnReadDay("600000.day");
}
//-----------------------------------------------
//从读取的数据中转换常用的浮点数价格
BOOL ConvertPrice(UINT price, double *fPrice)
{
double dbl;
UINT uTemp;
const UINT baseNumber=0xb0000000;
const double Thousand = 1000.0;
uTemp = price ^ baseNumber;
dbl = uTemp / Thousand;
*fPrice = dbl;
return TRUE;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。