📄 realtime.cpp
字号:
// Realtime.cpp : implementation file
////**************************************************************************************////
//* 实时线类*//
//******************************************************************************************//
#include "stdafx.h"
#include <afxwin.h>
#include <Windows.h>
#include "stock.h"
#include "Realtime.h"
#include "StockDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//静态变量
float CRealtime::m_fclose=0;
float CRealtime::m_fhighest=0;
float CRealtime::m_flowest=0;
CString CRealtime::m_sLastName;
int CRealtime::xPos;
int CRealtime::xPrev;
CData CRealtime::realdata;
int CRealtime::m; //横坐标(分钟数)
float CRealtime::M; //最大偏移量
float CRealtime::VolMax;
int CRealtime::Point[14400][2]; //对应的坐标值
int CRealtime::PointAver[14400][2]; //加权平均线的点
float CRealtime::Vol[14400]; //算出的成交量
int CRealtime::VPoint[14400][2];
float CRealtime::VolThis;
float CRealtime::VolLast;
IMPLEMENT_DYNCREATE(CRealtime, CView)
CRealtime::CRealtime()
{
ReStart();
realdata.m_strCode="";
realdata.m_strName="";
}
CRealtime::~CRealtime()
{
ReStart();
}
BEGIN_MESSAGE_MAP(CRealtime, CView)
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////
//获取数据函数
void CRealtime::GetData(CData& Data)
{
//获取数据
if(Data.m_strName!=m_sLastName)
{
realdata.m_strCode=_T("");
realdata.m_strName=_T("");
realdata.m_pAllData->m_RealData.RemoveAll();
ReStart();
}
realdata.m_strCode=Data.m_strCode;
realdata.m_strName=Data.m_strName;
int nCount=Data.m_pAllData->m_RealData.GetSize();
if(nCount<=1)
{
/* realdata.m_pAllData->m_RealData[0].New=0;
realdata.m_pAllData->m_RealData[0].Amount=0;
realdata.m_pAllData->m_RealData[0].Volume=0;
realdata.m_pAllData->m_RealData[0].Time=0;
realdata.m_pAllData->m_RealData.RemoveAll();*/
return;
}
else
{
realdata.m_pAllData->m_RealData.Add(Data.m_pAllData->m_RealData[nCount-1/*(nCount<428) ? i : (int)(((float)nCount)/428.0)*nCount]*/]); //横轴最多只可以显示428个点
m_fclose=Data.m_pAllData->m_KLine.LastClose;
ProcessData();
Invalidate();
m_sLastName=realdata.m_strName;
}
}
////////////////////////////////////////////////////////////////////////////
void CRealtime::ProcessData()
{
//计算要用的数据
//M值
Culculate();
M = ((m_fhighest-m_fclose) > (m_fclose-m_flowest)) ? ((m_fhighest-m_fclose)) * 1.5 : ((m_fclose-m_flowest)) * 1.5;
if ( M < (m_fclose*0.07) )
{
M = m_fclose*0.07;
}
//m值
m=realdata.m_pAllData->m_RealData.GetSize()-1;
int i;
if(m>428)
{
for(i=0;i<=m;i++)
{
realdata.m_pAllData->m_RealData[i].New=0;
realdata.m_pAllData->m_RealData[i].Amount=0;
realdata.m_pAllData->m_RealData[i].Volume=0;
realdata.m_pAllData->m_RealData[i].Time=0;
realdata.m_strCode=_T("");
realdata.m_strName=_T("");
m_fclose=0;
m_fhighest=0;
m_flowest=0;
ReStart();
}
}
//Vol[m], VolMax值
int j;
for(j=1;j<=m;j++)
{
if (m==0)
{
VolThis = realdata.m_pAllData->m_RealData[0].Volume;
Vol[m] = VolThis;
VolMax = VolThis;
}
else
{
VolThis=realdata.m_pAllData->m_RealData[j].Volume-VolLast;
VolThis=(VolThis>20) ? VolThis :20;
Vol[j] =( VolThis>0) ? VolThis :20.0 ;
if( VolThis>VolMax )
{
VolMax = VolThis;
}
}
VolLast = realdata.m_pAllData->m_RealData[j].Volume;
}
//计算横纵坐标
Exchange();
ExchangeA();
ExchangeV();
}
///////////////////////////////////////////////////////////////////////////////////////
//背景函数
void CRealtime::DrawBkgLine(CDC* pDC)
{
int i=0;
char chName[300];
CRect rect;
CPoint client;
CPen redpen(PS_SOLID,2,RGB(153,0,0));
CPen dashpen(PS_DOT,1,RGB(255,255,255));
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,255,255));
GetClientRect (&rect);
client.x=rect.right;
client.y=rect.bottom;
sprintf(chName, "%8s", realdata.m_strName);
pDC->TextOut(85, 20, chName, lstrlen(chName));
sprintf(chName, "%8s", realdata.m_strCode);
pDC->TextOut(180, 20, chName, lstrlen(chName));
//画边框日线边框
pDC->SelectObject(&redpen);
rect.left = 80;
rect.top = 40;
rect.right = client.x-80;
rect.bottom = client.y-80;
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(&rect);
//画下边框
rect.left = 80;
rect.top = client.y-60;
rect.right = client.x-80;
rect.bottom = client.y-10;
pDC->Rectangle(&rect);
//画横中间实线
for ( i =0; i<2; i++ )
{
pDC->MoveTo( 80, 40+(i+1)*((client.y-120)/3) );
pDC->LineTo( client.x-80, 40+(i+1)*((client.y-120)/3) );
}
//画中间竖实线
for ( i =0; i<3; i++ )
{
pDC->MoveTo( 80+(i+1)*((client.x-160)/4), 40 );
pDC->LineTo( 80+(i+1)*((client.x-160)/4), client.y-80 );
}
//背景虚线
pDC->SelectObject(&dashpen);
for ( i=0; i<5; i++ )
{
pDC->MoveTo( 80, 40+(i+1)*((client.y-120)/3/6) );
pDC->LineTo( client.x-80, 40+(i+1)*((client.y-120)/3/6) );
}
for ( i=6; i<11; i++ )
{
pDC->MoveTo( 80, 44+(i+1)*((client.y-120)/3/6) );
pDC->LineTo( client.x-80, 44+(i+1)*((client.y-120)/3/6) );
}
for ( i=12; i<17; i++ )
{
pDC->MoveTo( 80, 48+(i+1)*((client.y-120)/3/6) );
pDC->LineTo( client.x-80, 48+(i+1)*((client.y-120)/3/6) );
}
//画下边框内文字
sprintf(chName, "%8s", "◆股市有风险 祝君好运道");
pDC->TextOut(85, client.y-40, chName, lstrlen(chName));
//画时间信息
sprintf(chName, "%s","09:30");
pDC->TextOut(80, client.y-80, chName, lstrlen(chName));
sprintf(chName, "%s", "10:30");
pDC->TextOut(80+((client.x-160)/4), client.y-80, chName, lstrlen(chName));
sprintf(chName, "%s", "13:00");
pDC->TextOut(80+2*((client.x-160)/4), client.y-80, chName, lstrlen(chName));
sprintf(chName, "%s", "14:00");
pDC->TextOut(80+3*((client.x-160)/4), client.y-80, chName, lstrlen(chName));
sprintf(chName, "%s", "15:00");
pDC->TextOut(40+4*((client.x-160)/4), client.y-80, chName, lstrlen(chName));
}
////////////////////////////////////////////////////////////////////////////////////
//实时线函数
void CRealtime::DrawRealLine(CDC* pDC)
{
int i=0;
float M6=0,price=0;
float percent=0;
int V6=0;
int voly=0;
char chName[300];
CRect rect;
CPoint client;
CPen whitepen(PS_SOLID,1,RGB(255,255,255));
CPen yellowpen(PS_SOLID,1,RGB(255,255,0));
CPen blackpen(PS_SOLID,1,RGB(0,0,0));
GetClientRect (&rect);
client.x=rect.right;
client.y=rect.bottom;
pDC->SetBkMode(OPAQUE);
pDC->SetBkColor(RGB(0,0,0));
pDC->SetTextColor(RGB(255,255,255));
//画坐标值
M6=M/6;
if ( m>0 )
{
for ( i=0; i<13; i++ )
{
//左边
price=M6*(6-i)+m_fclose;
sprintf(chName, "%10.2f", price);
pDC->TextOut(0, 35+i*((client.y-120)/3/6), chName, lstrlen(chName));
//右边
percent=(M6*(6-i)/m_fclose)*100;
sprintf(chName, "%10.2f%%", percent);
pDC->TextOut(client.x-75, 35+i*((client.y-120)/3/6), chName, lstrlen(chName));
}
}
//画分时线
pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(&whitepen);
pDC->MoveTo(Point[0][0],Point[0][1]);
for( i=1; i<m; i++ )
{
pDC->LineTo(Point[i][0],Point[i][1]);
}
//加权平均线
pDC->SelectObject(&yellowpen);
pDC->MoveTo(PointAver[0][0],PointAver[0][1]);
for( i=1; i<m; i++ )
{
pDC->LineTo(PointAver[i][0],PointAver[i][1]);
}
//画成交量线
pDC->SelectObject(&yellowpen);
for( i=1; i<m; i++ )
{
pDC->MoveTo(82+i*2, client.y-85);
pDC->LineTo((VPoint[i][0]),((VPoint[i][1]>client.y-85)?(2*(client.y-85)-VPoint[i][1]):VPoint[i][1]));
}
//画成交量坐标值
V6 = VolMax/6;
if ( m>0 )
{
pDC->SelectObject(&blackpen);
rect.top = 35+13*(client.y-120)/3/6;
rect.bottom =35+17*(client.y-120)/3/6;
rect.left = 15;
rect.right = 75;
pDC->SelectStockObject(BLACK_BRUSH);
pDC->Rectangle(&rect);
for ( i=0; i<5; i++ )
{
voly=VolMax-V6*(i+1);
sprintf(chName, "%10.2d", voly);
pDC->TextOut(10, 35+(13+i)*(client.y-120)/3/6, chName, lstrlen(chName));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -