⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 realtime.cpp

📁 程序经过了调试,直接运行就可以显示结果,为股市应用程序,VC++的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
////////////////////////////////////////////////////////////////////////////////////////
//实时线刷新函数
void CRealtime::Refresh()
{
	
    int i=0;
	float M6=0,price=0;
	float percent=0;
	int	V6=0;
	int voly=0;
    char      chName[300];
	
    CClientDC     dc(this);
	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;
	
	dc.SetBkMode(OPAQUE);
	dc.SetBkColor(RGB(0,0,0));
	dc.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);
			dc.TextOut(0, 35+i*((client.y-120)/3/6), chName, lstrlen(chName));
			
			//右边
			percent=(M6*(6-i)/m_fclose)*100;
			sprintf(chName, "%10.2f%%", percent);
			dc.TextOut(client.x-75, 35+i*((client.y-120)/3/6), chName, lstrlen(chName));
		}
	}
	
	
	//画分时线
	if(m>1)
	{
		dc.SetBkMode(TRANSPARENT);	
		dc.SelectObject(&whitepen);
		
		dc.MoveTo(Point[m-1][0],Point[m-1][1]);	
		dc.LineTo(Point[m][0],Point[m][1]);
	}
	
	
	//加权平均线
	if(m>1)
	{
		dc.SelectObject(&yellowpen);
		
		dc.MoveTo(PointAver[m-1][0],PointAver[m-1][1]);	
		dc.LineTo(PointAver[m][0],PointAver[m][1]);
	}
	
	//画成交量线
	if(m>1)
	{
		dc.SelectObject(&yellowpen);
		
		dc.MoveTo(82+m*2, client.y-85);
		dc.LineTo((VPoint[m][0]),((VPoint[m][1]>client.y-85)?(2*(client.y-85)-VPoint[m][1]):VPoint[m][1]));
	}
	
	
	//画成交量坐标值
	V6 = VolMax/6;
	if ( m>0 )
	{
		dc.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;
		
		dc.SelectStockObject(BLACK_BRUSH);
		dc.Rectangle(&rect);
		for ( i=0; i<5; i++ )
		{ 	
			voly=VolMax-V6*(i+1);
			sprintf(chName, "%10.2d", voly);
			dc.TextOut(10, 35+(13+i)*(client.y-120)/3/6, chName, lstrlen(chName));
		}
	}
	
}
//////////////////////////////////////////////////////////////////////////////////////
void CRealtime::ReStart()	
{
	m=0;
	M=0;
	VolMax=1;//最大实时成交量	                    	     					 												
    xPos=0;
    xPrev=0;     
    VolThis=0.0;
	VolLast=0.0;
}
/////////////////////////////////////////////////////////////////////////////////////////////
//转换函数

void CRealtime::Exchange()//"分时线" 价格到坐标值的转换
{
	int x=0,i=0;
	
	CRect     rect;
	CPoint    client;
	
	GetClientRect (&rect);
	client.x=rect.right;
	client.y=rect.bottom;
	
	for ( i=0; i<m; i++ )
	{
		x = (int)((client.y-120)/3* (realdata.m_pAllData->m_RealData[i].New - m_fclose ) / M );//收到的价格

		Point[i][0]=82+i*2;//对应的坐标值
		Point[i][1]=40+(client.y-120)/3-x;
		Point[i][1]=(Point[i][1]>(40+(client.y-120)/3*2)) ?(40+(client.y-120)/3*2) : (40+(client.y-120)/3-x);
		Point[i][1]=(Point[i][1]<40) ?40 : (40+(client.y-120)/3-x);
	}	
}
///////////////////////////////////////////////////////////////////////////////////
void CRealtime::ExchangeA()//"分时线" 价格,成交量到加权平均线坐标的转换
{
	int x=0,i=0,j=0;
	float total1;
	float total2;
	float aver=0;	
    total1=0;
	total2=0;
	
	CRect     rect;
	CPoint    client;
	
	GetClientRect (&rect);
	client.x=rect.right;
	client.y=rect.bottom;
	
	for(j=0;j<m;j++)
	{
		for (i=0;i<=j;i++)
		{	 
			total1=total1+realdata.m_pAllData->m_RealData[i].New*Vol[i];//价格
			total2=total2+Vol[i];//成交量
		}
		
		aver=total1/total2;//加权平均
		
		x = (int)((client.y-120)/3 * ( aver - m_fclose ) / M );
		
		PointAver[j][0]=82+j*2;
		PointAver[j][1]=40+(client.y-120)/3-x;
		PointAver[j][1]=(PointAver[j][1]>40+(client.y-120)/3*2) ?(40+(client.y-120)/3*2) : (40+(client.y-120)/3-x);
		PointAver[j][1]=(PointAver[j][1]<40) ?40 : (40+(client.y-120)/3-x);
	}
}
/////////////////////////////////////////////////////////////////////////
void CRealtime::ExchangeV()//"分时线" 成交量到坐标值的转换
{
	int x=0,i=0;
	CRect     rect;
	CPoint    client;
	
	GetClientRect (&rect);
	client.x=rect.right;
	client.y=rect.bottom;
	
	for ( i=0; i<m; i++ )
	{
		x = (int)(((client.y-120)/3) *( ( Vol[i] ) / VolMax) );
		
//		
		VPoint[i][0]=82+i*2;
		VPoint[i][1]=40+(client.y-120)-x;
		
	}	
}
////////////////////////////////////////////////////////////////////////
void CRealtime::Culculate()
{    int i=0;
	m_fhighest=realdata.m_pAllData->m_RealData[0].New;
	m_flowest=realdata.m_pAllData->m_RealData[0].New;
	for(i=0;i<realdata.m_pAllData->m_RealData.GetSize();i++)
	{
		if(m_fhighest<realdata.m_pAllData->m_RealData[i].New)
			m_fhighest=realdata.m_pAllData->m_RealData[i].New;
		if(m_flowest>realdata.m_pAllData->m_RealData[i].New)
		    m_flowest=realdata.m_pAllData->m_RealData[i].New;
	}
}
/////////////////////////////////////////////////////////////////////////////
void CRealtime::OnLButtonDown(UINT nFlags, CPoint point)
{
	static int    lx=0,ly=0;
	int           x=0,y=0;
	
	CClientDC     dc(this);
	CRect     rect;
	CPoint    client;
	CPen          dashpen(PS_DOT,1,RGB(0,255,0));
	CPen          blackpen(PS_DOT,1,RGB(0,0,0));
    
	dc.SetBkMode(TRANSPARENT);
	dc.SelectObject(&dashpen);
	
	x = point.x;
	y = point.y;
	
	xPos=point.x;
	
	
	GetClientRect (&rect);
	client.x=rect.right;
	client.y=rect.bottom;
	
	if ( x>82 && x < client.x-82 )
	{
		dc.SelectObject(&dashpen);
		dc.MoveTo(x,40+2);
		dc.LineTo(x,40+((client.y-120)/3*2)-2);
		
		dc.SelectObject(&blackpen);
		dc.MoveTo(lx,40+2);
		dc.LineTo(lx,40+((client.y-120)/3*2)-2);
	}
	
	lx = point.x;
	ly = point.y;
	
}
///////////////////////////////////////////////////////////////////////////////
void CRealtime::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
{
	switch(nChar)
	{
		
	case VK_RIGHT:
		
		xPrev=xPos;
		xPos+=5;
		Keymove();
		break;
		
	case VK_LEFT:
		
	       xPrev=xPos;
		   xPos-=5;
           Keymove();
		   break;
		   
	default:
		break;
	}
}

void CRealtime::OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags )
{
	
}
//////////////////////////////////////////////////////////////////////////////////////
//左右键移动时的响应函数
void CRealtime::Keymove()
{ 
	int           x=0,y=0;
	
	CClientDC     dc(this);
	CRect     rect;
	CPoint    client;
	CPen          dashpen(PS_DOT,1,RGB(0,255,0));
	CPen          blackpen(PS_DOT,1,RGB(0,0,0));
	
	dc.SetBkMode(TRANSPARENT);
	dc.SelectObject(&dashpen);
	
	GetClientRect (&rect);
	client.x=rect.right;
	client.y=rect.bottom;
	
	if ((xPos>82 &&xPos< client.x-82)||(xPrev>82 &&xPrev< client.x-82) )
	{
		
		dc.SelectObject(&blackpen);
		dc.MoveTo(xPrev,40+2);
		dc.LineTo(xPrev,40+((client.y-120)/3*2)-2);
		
		dc.SelectObject(&dashpen);
		dc.MoveTo(xPos,40+2);
		dc.LineTo(xPos,40+((client.y-120)/3*2)-2);
		
	}
	
	
	
}
//////////////////////////////////////////////////////////////////

// CRealtime drawing

void CRealtime::OnDraw(CDC* pDC)
{   //设置视图背景
    CDocument* pDoc = GetDocument();
	
    ASSERT_VALID(pDoc); 
    CRect rectClient; 
    CBrush brushBkColor;     
    brushBkColor.CreateSolidBrush(RGB(0,0,0)); 
	
	GetClientRect(rectClient); 
    pDC->DPtoLP(rectClient); 
    pDC->FillRect(rectClient,&brushBkColor);
	
	
    DrawBkgLine(pDC);//背景
	
    DrawRealLine(pDC);//实时线
	
}

/////////////////////////////////////////////////////////////////////////////
// CRealtime diagnostics

#ifdef _DEBUG
void CRealtime::AssertValid() const
{
	CView::AssertValid();
}

void CRealtime::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CRealtime message handlers
CStockDoc* CRealtime::GetDocument()
{
	return (CStockDoc*)m_pDocument;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -