MFC_9.21_10:35 KlineMiddleView
程序员文章站
2024-03-23 11:31:40
...
9.21_10:35 KlineMiddleView
KlineMiddleView.h
#pragma once
#include "afxwin.h"
#include "ClientDoc.h"
class CKlineMiddleView :
public CView
{
DECLARE_DYNCREATE(CKlineMiddleView)
public:
CKlineMiddleView(void);
~CKlineMiddleView(void);
protected:
virtual void OnDraw(CDC* pDC);
public:
DECLARE_MESSAGE_MAP();
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
void KlinePaint(void);//画K线
void XlinePaint(void);//画坐标线
void XlineDel(void);
};
#pragma once
KlineMiddleView.cpp
#include "StdAfx.h"
#include "Client.h"
#include "MainFrm.h"
#include <math.h>
#include "KlineMiddleView.h"
IMPLEMENT_DYNCREATE(CKlineMiddleView , CView)
CKlineMiddleView::CKlineMiddleView(void){}
CKlineMiddleView::~CKlineMiddleView(void){}
void CKlineMiddleView::OnDraw(CDC*)
{
// TODO: 在此添加专用代码和/或调用基类
this->KlinePaint();
}
// KlineLeftView.cpp : 实现文件
//
BEGIN_MESSAGE_MAP(CKlineMiddleView, CView)
ON_WM_MOUSEWHEEL()
ON_WM_LBUTTONDOWN()
ON_WM_CREATE() //初始化函数,生成随机数
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
CDC* pDC;
CRect rect;
CDC MemDC; //首先定义一个显示设备对象
CBitmap MemBitmap;//定义一个位图对象
BITMAP bm;
int m_Wheel=20; //记录滚轮
int px,py,pxf,pxy = 0; //画坐标线能用到
int ScreenHeight,ScreenWidth,ScreenCenter;
BOOL CKlineMiddleView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: 在此添加消息处理程序代码和/或调用默认
m_Wheel += zDelta*0.01;
if(m_Wheel >=40) m_Wheel=40;
else if(m_Wheel <= 10) m_Wheel=10;
pDC = GetWindowDC();
//pDC->FillSolidRect(rect, RGB(0,0,0)); //设背景为黑色
int ShowWidth = bm.bmWidth*m_Wheel/10;
MemBitmap.GetBitmap(&bm);
pDC->StretchBlt(ScreenWidth- ShowWidth, 0, ShowWidth, bm.bmHeight,
&MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
//放大缩小以右边为不动的轴
return CView::OnMouseWheel(nFlags, zDelta, pt);
}
void CKlineMiddleView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CView::OnLButtonDown(nFlags, point);
}
int CKlineMiddleView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CClientDoc* pDoc = (CClientDoc*)GetDocument();
pDoc->m_DataKLine=new KLINEDATA[100];
for(int i=0;i<100;i++)
{
pDoc->m_DataKLine[i].KOpenPrice = sin((double)i*0.2)*160;
pDoc->m_DataKLine[i].KClosePrice = pDoc->m_DataKLine[i].KOpenPrice + rand()%320 - 160;
pDoc->m_DataKLine[i].KHighestPrice = max(pDoc->m_DataKLine[i].KOpenPrice,pDoc->m_DataKLine[i].KClosePrice)*1.2;
pDoc->m_DataKLine[i].KLowestPrice = min(pDoc->m_DataKLine[i].KOpenPrice,pDoc->m_DataKLine[i].KClosePrice)*0.8;
}
return 0;
}
void CKlineMiddleView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
ScreenToClient(&point);
px = point.x ;
py = point.y ;
CView::OnMouseMove(nFlags, point);
}
void CKlineMiddleView::KlinePaint(void)
{
pDC = GetWindowDC();
pDC->GetClipBox(&rect);
pDC->FillSolidRect(rect, RGB(0,0,0)); //设背景为黑色
ScreenHeight = rect.Height();
ScreenWidth = rect.Width();
ScreenCenter = ScreenWidth /2;
CClientDoc* pDoc = (CClientDoc*)GetDocument(); //载入数据的结构体
//建立一个与屏幕显示兼容的位图
MemBitmap.DeleteObject();
MemDC.DeleteDC(); //清除上一次位图
MemDC.CreateCompatibleDC(NULL);
MemBitmap.CreateCompatibleBitmap(pDC,ScreenWidth,ScreenHeight);
CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap);
MemDC.FillSolidRect(0,0,ScreenWidth,ScreenHeight,RGB(0,0,0));
int KWidth = ScreenWidth / 100; //每个k的宽度
int CLine = ScreenHeight/2; //隐形基准轴
for(int i=0;i<100;i++)
{
int xleftTop = KWidth*(i+1.2);
int xWidth = KWidth*0.6;
if(pDoc->m_DataKLine[i].KOpenPrice > pDoc->m_DataKLine[i].KClosePrice)
{
int yleftTop = CLine - pDoc->m_DataKLine[i].KOpenPrice;
int yHeight = pDoc->m_DataKLine[i].KOpenPrice - pDoc->m_DataKLine[i].KClosePrice;
MemDC.FillSolidRect(xleftTop,yleftTop,xWidth,yHeight,RGB(39,176,216));
CPen PenBlue(PS_SOLID,1,RGB(39,176,216));
CPen *oldPenx = MemDC.SelectObject(&PenBlue);
MemDC.MoveTo( xleftTop + xWidth/2 , CLine - pDoc->m_DataKLine[i].KHighestPrice);
MemDC.LineTo( xleftTop + xWidth/2 , CLine - pDoc->m_DataKLine[i].KLowestPrice);
}
else if(pDoc->m_DataKLine[i].KOpenPrice < pDoc->m_DataKLine[i].KClosePrice)
{
int yleftTop = CLine - pDoc->m_DataKLine[i].KClosePrice;
int yHeight = pDoc->m_DataKLine[i].KClosePrice - pDoc->m_DataKLine[i].KOpenPrice;
MemDC.FillSolidRect(xleftTop,yleftTop,xWidth,yHeight,RGB(255,74,102));
CPen PenRed(PS_SOLID,1,RGB(255,74,102));
CPen *oldPenx = MemDC.SelectObject(&PenRed);
MemDC.MoveTo( xleftTop + xWidth/2 , CLine - pDoc->m_DataKLine[i].KHighestPrice);
MemDC.LineTo( xleftTop + xWidth/2 , CLine - pDoc->m_DataKLine[i].KLowestPrice);
}
else //画open和close相等的白线
{
int yleftTop = CLine - pDoc->m_DataKLine[i].KOpenPrice;
int yHeight = 1;
MemDC.FillSolidRect(xleftTop,yleftTop,xWidth,yHeight,RGB(255,255,255));
CPen PenWhite(PS_SOLID,1,RGB(255,255,255));
CPen *oldPenx = MemDC.SelectObject(&PenWhite);
MemDC.MoveTo( xleftTop + xWidth/2 , CLine - pDoc->m_DataKLine[i].KHighestPrice);
MemDC.LineTo( xleftTop + xWidth/2 , CLine - pDoc->m_DataKLine[i].KLowestPrice);
}
int ShowWidth = bm.bmWidth*m_Wheel/10;
MemBitmap.GetBitmap(&bm);
pDC->StretchBlt(ScreenWidth- ShowWidth, 0, ShowWidth, bm.bmHeight,
&MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
//MemBitmap.GetBitmap(&bm);
//pDC->StretchBlt(0, 0, bm.bmWidth*m_Wheel/30, bm.bmHeight,
// &MemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
}
}
void CKlineMiddleView::XlinePaint(void)
{
}
void CKlineMiddleView::XlineDel(void)
{
}
上一篇: typedef与#define
推荐阅读
-
MFC_9.21_10:35 KlineMiddleView
-
软件测试真的干到35就干不动了吗?
-
python 刷 leetcode 题目(35)
-
35.从零开始学springboot-数据库版本管理Flyway
-
AjaxControlToolkit-Framework35SP1.zip 博客分类: ASP.NET
-
我画了35张图就是为了让你深入 AQS
-
WEB前端:vuejs全家桶(35):模块化开发:vue-router模块化、自定义组件添加事件
-
LeetCode 35. 搜索插入位置 Search Insert Position(C语言)
-
【leetcode】35. Search Insert Position 给定数字插入有序数组的下标点
-
Java中性能优化的35种方法汇总