MFC_10.11_模拟K线和真实K线

KlineLeftView.h

#pragma once
#include "afxwin.h"

// CKlineLeftView 窗体视图

class CKlineLeftView : public CFormView
{
   
	DECLARE_DYNCREATE(CKlineLeftView)

protected:
	CKlineLeftView();           // 动态创建所使用的受保护的构造函数
	virtual ~CKlineLeftView();

public:
	enum {
    IDD = IDD_FORMVIEW_LEFT };
#ifdef _DEBUG
	virtual void AssertValid() const;
#ifndef _WIN32_WCE
	virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
    virtual void OnInitialUpdate();
protected:
    virtual void OnDraw(CDC* /*pDC*/);

public:
    afx_msg void OnStnClickedKonemin();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	void Updata(int IDP);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	void RePaint(void);
	CDC* pDC;
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	CRect rect;

};


#pragma once

KlineLeftView.cpp

#include "stdafx.h"
#include "Client.h"
#include "KlineLeftView.h"

// KlineLeftView.cpp : 实现文件
//
CKlineLeftView *Lv;
int IDpoint=0;
int M_IDpoint=0;

IMPLEMENT_DYNCREATE(CKlineLeftView, CFormView)

CKlineLeftView::CKlineLeftView()
	: CFormView(CKlineLeftView::IDD)
{
   
}

CKlineLeftView::~CKlineLeftView()
{
   
}

void CKlineLeftView::DoDataExchange(CDataExchange *pDX)
{
   
	CFormView::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CKlineLeftView, CFormView)
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_TIMER()
END_MESSAGE_MAP()

// CKlineLeftView 诊断

#ifdef _DEBUG
void CKlineLeftView::AssertValid() const
{
   
	CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void CKlineLeftView::Dump(CDumpContext &dc) const
{
   
	CFormView::Dump(dc);
}
#endif
#endif //_DEBUG

// CKlineLeftView 消息处理程序

void CKlineLeftView::OnInitialUpdate()
{
   
	CFormView::OnInitialUpdate();

	// TODO: 在此添加专用代码和/或调用基类
}

void CKlineLeftView::OnDraw(CDC *pDC)
{
   
	// TODO: 在此添加专用代码和/或调用基类


	GetClientRect(&rect);
	pDC->FillSolidRect(&rect, RGB(0,0,0)); 
	rect.DeflateRect(0,40,0,0);

	//CClientDC pDC(Lv);
	/*
	CRect rect;
	GetClientRect(&rect);
	pDC->FillSolidRect(&rect, RGB(0,0,0)); 
	rect.DeflateRect(0,40,0,0);
	pDC->FillSolidRect(&rect, RGB(20, 32, 52));*/
	this->RePaint();
}

void CKlineLeftView::OnSize(UINT nType, int cx, int cy)
{
   
	CView::OnSize(nType, cx, cy);

	// TODO: 在此处添加消息处理程序代码
}

void CKlineLeftView::Updata(int IDP)
{
   
	if(IDP>0)
	{
   
		IDpoint=IDP;
		M_IDpoint=0;
	}
	else if(IDP<0)
	{
   
		M_IDpoint=-IDP;
		IDpoint=0;
	}
	else
	{
   
		M_IDpoint=0;
		IDpoint=0;
	}

	CString str;
	str.Format("%d------%d\n",IDpoint,M_IDpoint);
	//OutputDebugString(str);
	
	
	//pDC->TextOut(0,15,pDoc->m_DataKLine[IDpoint].KLowestPrice);
	//pDoc->m_DataKLine[IDpoint]
}

int CKlineLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	SetTimer(1,300,NULL);
	Lv = this;
	return 0;
}

void CKlineLeftView::RePaint(void)
{
   
	CDC* pDC;
	pDC = GetWindowDC();

	//CClientDC pDC(Lv);
	pDC->FillSolidRect(&rect, RGB(20, 32, 52));

	CPen PenBlueTop(PS_SOLID,5,RGB(23,65,102));
	pDC->SelectObject(&PenBlueTop);
	pDC->MoveTo(rect.left,rect.top);      
	pDC->LineTo(rect.right,rect.top);
	//rect.top += 20;


	int liStart=rect.top + 20;
	int SpaLine=80;

	CClientDoc *pDoc = (CClientDoc *)GetDocument(); //载入数据的结构体

	CFont font;//数字
	font.CreatePointFont(110, "微软雅黑");
	pDC->SelectObject(&font);
	SetTextColor(*pDC, RGB(255, 255, 255));
	SetBkMode(*pDC, TRANSPARENT);
	pDC->TextOut(rect.left + 5, liStart, "开盘价");
	pDC->TextOut(rect.left + 5, liStart+SpaLine*1, "最高价");
	pDC->TextOut(rect.left + 5, liStart+SpaLine*2, "最低价");
	pDC->TextOut(rect.left + 5, liStart+SpaLine*3, "收盘价");

	liStart=liStart+SpaLine*4+40;
	pDC->TextOut(rect.left + 5, liStart, "成交量");
	pDC->TextOut(rect.left + 5, liStart+SpaLine*1, "持仓量");
	pDC->TextOut(rect.left + 10, liStart+SpaLine*2, "结算");

	/*
	pDC.TextOut(rect.left+15,rect.top+600,"1m");
	pDC.TextOut(rect.left+15,rect.top+640,"3m");
	pDC.TextOut(rect.left+15,rect.top+680,"5m");
	pDC.TextOut(rect.left+15,rect.top+720,"10m");
	pDC.TextOut(rect.left+15,rect.top+760,"1H");
	pDC.TextOut(rect.left+15,rect.top+800,"1D");
	pDC.TextOut(rect.left+15,rect.top+840,"1W");
*/
}


void CKlineLeftView::OnTimer(UINT_PTR nIDEvent)
{
   
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CDC* pDC;
	pDC = GetWindowDC();
	CClientDoc* pDoc = (CClientDoc*)GetDocument(); //载入数据的结构体

	switch (nIDEvent)   
	{
     
	case 1:   //定时器1,显示右下角倒计时
		{
   	
			CString KH, KL, KO, KC, MCO, PCent;
			//CRect rect;
			//GetClientRect(&rect);
			CFont font;//数字
			font.CreatePointFont(110, "微软雅黑");
			pDC->SelectObject(&font);
			SetTextColor(*pDC, RGB(255, 255, 255));
			SetBkMode(*pDC, TRANSPARENT);
			int liStart=rect.top + 40;
			int SpaLine=80;

			CString str;
			str.Format("%d------%d\n",IDpoint,M_IDpoint);
			OutputDebugString(str);

			if(IDpoint)
			{
   
				this->RePaint();
				KH.Format("%.2f", pDoc->m_DataSrvToClient.at(IDpoint)->KHighestPrice);
				KL.Format("%.2f", pDoc->m_DataSrvToClient.at(IDpoint)->KLowestPrice);
				KO.Format("%.2f", pDoc->m_DataSrvToClient.at(IDpoint)->KOpenPrice);
				KC.Format("%.2f", pDoc->m_DataSrvToClient.at(IDpoint)->KClosePrice);

				//开盘价调色
				if (IDpoint == 0)
					SetTextColor(*pDC, RGB(255, 74, 102));
				else if (pDoc->m_DataSrvToClient.at(IDpoint)->KOpenPrice >= pDoc->m_DataSrvToClient.at(IDpoint - 1)->KOpenPrice)
					SetTextColor(*pDC, RGB(255, 74, 102));
				else
					SetTextColor(*pDC, RGB(34, 177, 54));

				pDC->TextOut(rect.left + 3, liStart, KO);

				//最高价调色
				if (pDoc->m_DataSrvToClient.at(IDpoint)->KHighestPrice >= pDoc->m_DataSrvToClient.at(IDpoint)->KOpenPrice)
					SetTextColor(*pDC, RGB(255, 74, 102));
				else
					SetTextColor(*pDC, RGB(34, 177, 54));

				pDC->TextOut(rect.left + 3, liStart+SpaLine*1, KH);

				//最低价调色
				if (pDoc->m_DataSrvToClient.at(IDpoint)->KLowestPrice >= pDoc->m_DataSrvToClient.at(IDpoint)->KOpenPrice)
					SetTextColor(*pDC, RGB(255, 74, 102));
				else
					SetTextColor(*pDC, RGB(34, 177, 54));

				pDC->TextOut(rect.left + 3, liStart+SpaLine*2, KL);

				//收盘价调色
				if (pDoc->m_DataSrvToClient.at(IDpoint)->KClosePrice >= pDoc->m_DataSrvToClient.at(IDpoint)->KOpenPrice)
					SetTextColor(*pDC, RGB(255, 74, 102));
				else
					SetTextColor(*pDC, RGB(34, 177, 54));

				pDC->TextOut(rect.left + 3, liStart+SpaLine*3, KC);
				float MinusCO = pDoc->m_DataSrvToClient.at(IDpoint)->KClosePrice - pDoc->m_DataSrvToClient.at(IDpoint)->KOpenPrice;
				MCO.Format("%.2f", MinusCO);
				PCent.Format("%.2f%%", MinusCO / pDoc->m_DataSrvToClient.at(IDpoint)->KOpenPrice);
				pDC->TextOut(rect.left + 3, liStart+SpaLine*3+20, MCO);
				pDC->TextOut(rect.left + 3, liStart+SpaLine*3+40, PCent);

				liStart=liStart+SpaLine*4+40;
				//成交量
				SetTextColor(*pDC, RGB(255, 242, 0));
				pDC->TextOut(rect.left + 3, liStart, "65");
				pDC->TextOut(rect.left + 3, liStart+20, "8");

				//持仓量
				pDC->TextOut(rect.left + 3, liStart+SpaLine*1, "31891");
				pDC->TextOut(rect.left + 3, liStart+SpaLine*1+20, "24");

				//结算
				pDC->TextOut(rect.left + 3, liStart+SpaLine*2, "3434.0");
			}
			else if(M_IDpoint)
			{
   
				this->RePaint();
				KH.Format("%.2f",pDoc->m_DataKLine[M_IDpoint].KHighestPrice);
				KL.Format("%.2f",pDoc->m_DataKLine[M_IDpoint].KLowestPrice);
				KO.Format("%.2f",pDoc->m_DataKLine[M_IDpoint].KOpenPrice);
				KC.Format("%.2f",pDoc->m_DataKLine[M_IDpoint].KClosePrice);

				//开盘价调色
				if(IDpoint==0)
					SetTextColor(*pDC, RGB(255,74,102));
				else if(pDoc->m_DataKLine[M_IDpoint].KOpenPrice>=pDoc->m_DataKLine[M_IDpoint-1].KOpenPrice)
					SetTextColor(*pDC, RGB(255,74,102));
				else 
					SetTextColor(*pDC, RGB(34,177,54));
				pDC->TextOut(rect.left+3,liStart,KO);

				//最高价调色
				if(pDoc->m_DataKLine[M_IDpoint].KHighestPrice>=pDoc->m_DataKLine[M_IDpoint].KOpenPrice)
					SetTextColor(*pDC, RGB(255,74,102));
				else 
					SetTextColor(*pDC, RGB(34,177,54));

				pDC->TextOut(rect.left+3,liStart+SpaLine*1,KH);


				//最低价调色
				if(pDoc->m_DataKLine[M_IDpoint].KLowestPrice>=pDoc->m_DataKLine[M_IDpoint].KOpenPrice)
					SetTextColor(*pDC, RGB(255,74,102));
				else 
					SetTextColor(*pDC, RGB(34,177,54));

				pDC->TextOut(rect.left+3,liStart+SpaLine*2,KL);



				//收盘价调色
				if(pDoc->m_DataKLine[M_IDpoint].KClosePrice>=pDoc->m_DataKLine[M_IDpoint].KOpenPrice)	
					SetTextColor(*pDC, RGB(255,74,102));
				else 
					SetTextColor(*pDC, RGB(34,177,54));

				pDC->TextOut(rect.left+3,liStart+SpaLine*3,KC);
				float MinusCO = pDoc->m_DataKLine[M_IDpoint].KClosePrice - pDoc->m_DataKLine[M_IDpoint].KOpenPrice;
				MCO.Format("%.2f",MinusCO);
				PCent.Format("%.2f%%",MinusCO/pDoc->m_DataKLine[M_IDpoint].KOpenPrice);
				pDC->TextOut(rect.left+3,liStart+SpaLine
  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值