📄 dlgplot.cpp
字号:
// dlgPlot.cpp : implementation file
//
#include "stdafx.h"
#include "StockDataParse.h"
#include "dlgPlot.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// dlgPlot dialog
dlgPlot::dlgPlot(CWnd* pParent /*=NULL*/)
: CDialog(dlgPlot::IDD, pParent)
{
//{{AFX_DATA_INIT(dlgPlot)
m_uiStartTime = 19990101;
m_uiStopTime = 20050101;
//}}AFX_DATA_INIT
}
void dlgPlot::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(dlgPlot)
DDX_Control(pDX, IDC_STATIC_PLOT, m_PLOT_SHOW);
DDX_Text(pDX, IDC_EDIT1, m_uiStartTime);
DDV_MinMaxUInt(pDX, m_uiStartTime, 19900000, 20090101);
DDX_Text(pDX, IDC_EDIT2, m_uiStopTime);
DDV_MinMaxUInt(pDX, m_uiStopTime, 20000000, 20091010);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(dlgPlot, CDialog)
//{{AFX_MSG_MAP(dlgPlot)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BTN_REPLOT, OnBtnReplot)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// dlgPlot message handlers
int dlgPlot::PlotKLine()
{
CDC* pDC;
//CWnd* pAppFrame =AfxGetApp()->m_pMainWnd;
//pDC =GetDesktopWindow( )->GetDC();
// pDC = pAppFrame->get->GetDC();//->GetWindowDC();
//pDC = GetWindowDC();
/*
pDC = m_PLOT_SHOW.GetWindowDC();
pDC=CWnd::GetDC();*/
pDC=m_PLOT_SHOW.GetWindowDC();
/*
CRect RectClient,Workarea;
GetClientRect(RectClient);
const int iClientRatio = 20;
const int iWorkareaRatio = 10;
Workarea.left=RectClient.left + RectClient.Width()/iClientRatio;
Workarea.right=RectClient.right-RectClient.Width()/iClientRatio;
Workarea.top=RectClient.top - RectClient.Height()/iClientRatio/2;
Workarea.bottom=RectClient.bottom-RectClient.Height()/iClientRatio;
//draw price
std::list<float> myfList ;*/
// DrawDCMap(pDC,Workarea,m_List_ST_StockInfoQ,m_List_ST_StockInfoQ.size());
DrawDCMap(pDC,m_List_ST_StockInfoQ,m_List_ST_StockInfoQ.size());
return 0;
}
// int dlgPlot::DrawDCMap(CDC* pDC, CRect Rect, List_ST_StockInfoQ myStockInfoList,int i_listLen)
int dlgPlot::DrawDCMap(CDC* pDC, List_ST_StockInfoQ myStockInfoList,int i_listLen)
{
CWnd *wnd=pDC->GetWindow();
CRect rect;
wnd->GetClientRect(rect);
CBrush backBrush(RGB(0,0,0)),*oldBrush;
oldBrush=pDC->SelectObject(&backBrush);
pDC->Rectangle(rect);
int rectHeigh=rect.bottom;
int rectWide=rect.right;
List_ST_StockInfoQ::iterator iter;
double hMaxPrice=0.0,hMinPrice=1000000.0;
double hMaxVolum =0.0;
iter=myStockInfoList.begin();
int iListLength = myStockInfoList.size()-1;
for(;iter!=myStockInfoList.end();iter++)
{
if( (iter->stPriceInfo.fHighPrice) > hMaxPrice)
{
hMaxPrice = iter->stPriceInfo.fHighPrice;
}
if((iter->stPriceInfo.fLowPrice) <hMinPrice)
{
hMinPrice = iter->stPriceInfo.fLowPrice;
}
if(iter->fHandCount > hMaxVolum)
{
hMaxVolum = iter->fHandCount;
}
}
double xDis,yDis,xLen,yLen;
xDis=(1.0/20.0)*rectWide;
yDis=(1.0/100.0)*rectHeigh;
const int ciXGridNumber = 10;
const int ciYGridNumber = 20;
xLen=(rectWide-xDis)/ciXGridNumber;
yLen=(rectHeigh-yDis)/ciYGridNumber;
CPen rectPen,*oldRectPen;
rectPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
oldRectPen=pDC->SelectObject(&rectPen);
pDC->Rectangle(CRect(xDis,yDis,xDis+ciXGridNumber*xLen,yDis+ciYGridNumber*yLen));
pDC->SelectObject(oldBrush);
for(int i=1;i<=ciYGridNumber-1;i++)
{
pDC->MoveTo(xDis,yDis+i*yLen);
pDC->LineTo(xDis+ciXGridNumber*xLen,yDis+i*yLen);
}
for(i=1;i<=ciXGridNumber-1;i++)
{
pDC->MoveTo(xDis+i*xLen,yDis);
pDC->LineTo(xDis+i*xLen,yDis+ciYGridNumber*yLen);
}
pDC->SelectObject(oldRectPen);
//int num=50;
double kWide=xLen*ciXGridNumber/iListLength;
double disIndex=yLen*ciYGridNumber*0.6/(hMaxPrice-hMinPrice);
double nMaxPrice,nMinPrice,nOpenPrice,nClosePrice;
i=1;
iter = myStockInfoList.begin();
for(;iter!=myStockInfoList.end();iter++,i++)
{
nMaxPrice =iter->stPriceInfo.fHighPrice;
nMinPrice = iter->stPriceInfo.fHighPrice;
nOpenPrice = iter->stPriceInfo.fOpenPrice;
nClosePrice = iter->stPriceInfo.fClosePrice;
CBrush brush;
CPen pen,*oldPen;
if(nOpenPrice<nClosePrice) //red
{
brush.CreateSolidBrush(RGB(255,0,0));
pen.CreatePen(PS_SOLID,1,RGB(255,0,0));
oldBrush=pDC->SelectObject(&brush);
oldPen=pDC->SelectObject(&pen);
pDC->Rectangle(CRect((xDis+(i-1)*kWide+kWide*0.2),(14*yLen+yDis-(nClosePrice-hMinPrice)*disIndex),(xDis+kWide*i),(14*yLen+yDis-(nOpenPrice-hMinPrice)*disIndex)));
pDC->MoveTo((xDis+(i-1)*kWide+kWide*0.5),(14*yLen+yDis-(nClosePrice-hMinPrice)*disIndex));
pDC->LineTo((xDis+(i-1)*kWide+kWide*0.5),(14*yLen+yDis-(nMaxPrice-hMinPrice)*disIndex));
pDC->MoveTo((xDis+(i-1)*kWide+kWide*0.5),(14*yLen+yDis-(nOpenPrice-hMinPrice)*disIndex));
pDC->LineTo((xDis+(i-1)*kWide+kWide*0.5),(14*yLen+yDis-(nMinPrice-hMinPrice)*disIndex));
// SelectObject(oldBrush)
}
else //green
{
brush.CreateSolidBrush(RGB(0,255,0));
oldBrush=pDC->SelectObject(&brush);
pen.CreatePen(PS_SOLID,1,RGB(0,255,0));
oldPen=pDC->SelectObject(&pen);
pDC->Rectangle(CRect((xDis+(i-1)*kWide+kWide*0.2),(14*yLen+yDis-(nOpenPrice-hMinPrice)*disIndex),(xDis+kWide*i),(14*yLen+yDis-(nClosePrice-hMinPrice)*disIndex)));
pDC->MoveTo((xDis+(i-1)*kWide+kWide*0.5),(14*yLen+yDis-(nOpenPrice-hMinPrice)*disIndex));
pDC->LineTo((xDis+(i-1)*kWide+kWide*0.5),(14*yLen+yDis-(nMinPrice-hMinPrice)*disIndex));
pDC->MoveTo((xDis+(i-1)*kWide+kWide*0.5),(14*yLen+yDis-(nClosePrice-hMinPrice)*disIndex));
pDC->LineTo((xDis+(i-1)*kWide+kWide*0.5),(14*yLen+yDis-(nMaxPrice-hMinPrice)*disIndex));
}
pDC->SelectObject(&oldPen);
pDC->SelectObject(&oldBrush);
}
//成交量
int MaxAver=int(hMaxVolum);
int shareMinute;
double disX=ciXGridNumber*xLen/(iListLength);
double disY=10*yLen/MaxAver;
//////////////////////////////////////////////////////////////////////////
i=1;
iter = myStockInfoList.begin();
const int ciInterVal = 9;
int iTime[ciInterVal]={0};
int iTimeStep =0;
for(;iter!=myStockInfoList.end();iter++,i++)
{
if(0 ==(i%((int)(iListLength/ciInterVal))) )
{
if(iTimeStep <ciXGridNumber)
{
iTime[iTimeStep] = iter->iDate;
iTimeStep++;
}
}
CBrush brush;
CPen pen,*oldPen;
pen.CreatePen(PS_SOLID,1,RGB(255,255,0));
brush.CreateSolidBrush(RGB(255,255,0));
shareMinute=(int)(iter->fHandCount);
oldPen=pDC->SelectObject(&pen);
oldBrush=pDC->SelectObject(&brush);
pDC->Rectangle(CRect((xDis+disX*i),(ciYGridNumber*yLen+yDis-shareMinute*disY),(xDis+disX*(i+1)),(ciYGridNumber*yLen+yDis)));
pDC->SelectObject(&oldPen);
pDC->SelectObject(&oldBrush);
}
CFont font,*oldFont;
double disPrice=(hMaxPrice-hMinPrice)/14.0;
int fontSize=xDis*0.4;
font.CreateFont(fontSize,0,0,0,
FW_NORMAL,
0,0,0,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH|FF_SWISS,
"宋体");
pDC->SetTextColor(RGB(255,0,0));
oldFont=pDC->SelectObject(&font);
pDC->SetBkColor(RGB(0,0,0));
for(i=0;i<15;i++)
{
if((hMaxPrice-i*disPrice)==(hMaxPrice+hMinPrice)/2)
pDC->SetTextColor(RGB(255,255,255));
if((hMaxPrice-i*disPrice)<(hMaxPrice+hMinPrice)/2)
pDC->SetTextColor(RGB(0,255,0));
CString price;
price.Format("%3.2f",float(hMaxPrice-i*disPrice));
pDC->TextOut(0.1*xDis,i*yLen-yDis/2,price);
//
/*
price.Format("%3.2f",100*2*(hMaxPrice-i*disPrice-(hMaxPrice+hMinPrice)/2)/(hMaxPrice+hMinPrice));
pDC->TextOut(0.1*xDis+xLen*4+xDis,i*yLen-yDis/2,price); */
}
//
pDC->SetTextColor(RGB(255,255,0));
for(i=0;i<ciXGridNumber;i++)
{
CString count;
count.Format("%d",MaxAver*(ciXGridNumber-i)/10);
pDC->TextOut(0.1*xDis,(15+i)*yLen-yDis/2,count);
}
//时间
pDC->SetTextColor(RGB(255,255,255));
for(i=0;i<ciXGridNumber;i++)
{
CString strTime;
strTime.Format("%d",iTime[i]);
pDC->TextOut(0.5*xDis+(i * xLen),ciYGridNumber*yLen+yDis,strTime);
}
return 0;
}
void dlgPlot::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
PlotKLine();
// Do not call CDialog::OnPaint() for painting messages
}
//void dlgPlot::OnButtonShow()
//{
// // TODO: Add your control notification handler code here
// //PlotKLine();
void dlgPlot::OnBtnReplot()
{
// TODO: Add your control notification handler code here
List_ST_StockInfoQ oList_ST_StockInfoQ;
List_ST_StockInfoQ::iterator iter;
UpdateData(TRUE);
if(m_uiStartTime >m_uiStopTime)
{
AfxMessageBox("Time Error! start time must less than stop time");
return ;
}
iter = m_List_ST_StockInfoQ.begin();
for(;iter!=m_List_ST_StockInfoQ.end();++iter)
{
if((iter->iDate>=m_uiStartTime)&&(iter->iDate <=m_uiStopTime))
{
oList_ST_StockInfoQ.push_back(*iter);;
}
}
//////////////////////////////////////////////////////////////////////////
CDC* pDC;
pDC=m_PLOT_SHOW.GetWindowDC();
DrawDCMap(pDC,oList_ST_StockInfoQ,oList_ST_StockInfoQ.size());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -