双缓冲区画图的问题
时间:2011-12-04
来源:互联网
typedef struct StockDay
{
unsigned long m_lDate; //日期
long m_lOpenPrice; //开
long m_lMaxPrice; //高
long m_lMinPrice; //低
long m_lClosePrice; //收
long m_lMoney; //成交金额
unsigned long m_lTotal; //成交量 单位:百股(手)
long m_lNoUse1; //未使用
long m_lNoUse2; //未使用
long m_lNoUse3; //未使用
}StockDay;
void CMidView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code here
StockDay *stock;
CRect rc;
GetClientRect(&rc);
CDC dcMem; //用于缓冲作图的内存DC
CBitmap bmp; //内存中承载临时图象的位图
dcMem.CreateCompatibleDC(pDC); //依附窗口DC创建兼容内存DC
bmp.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());//创建兼容位图
dcMem.SelectObject(&bmp); //将位图选择进内存DC
//按原来背景填充客户区,不然会是黑色
dcMem.FillSolidRect(rc,RGB(0,0,0));
int m_Low = 0;
int m_High = 1024;
int i;
int m_left,m_top,m_right,m_bottom;
int m_Interval = (m_High - m_Low)/10;
if (m_Interval < 1) m_Interval = 1;
m_left = rc.Width() /15;
m_top = rc.top+10;
m_right = rc.right-10;
m_bottom =99*rc.bottom/100;
int m_IntervalPan = (m_right - m_left)/11;
if (m_IntervalPan < 1 ) m_IntervalPan =1;
CPen curPen;
curPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
CPen* pOldPen=dcMem.SelectObject(&curPen);
// 绘制坐标轴
dcMem.MoveTo(m_left,m_top);
// 垂直轴
dcMem.LineTo(m_left,m_bottom);
// 水平轴
dcMem.LineTo(m_right,m_bottom);
dcMem.SelectObject(pOldPen);
// 写X轴刻度值
for (int y=m_bottom+25; y>=0; y-=m_bottom/6)
{
CRect rcc;
dcMem.MoveTo(75, y);
dcMem.LineTo(m_left, y);
dcMem.SetTextColor(RGB(255,0,0));
dcMem.Rectangle(&rcc);
dcMem.FillSolidRect(&rcc,RGB(0,0,0));
//CClientDC dc(this);
CFont font;
font.CreatePointFont(110,"宋体");
CFont *pOldFont=pDC->SelectObject(&font);
dcMem.SetTextColor(RGB(255,0,0));
dcMem.TextOut(30,250,"1.22");
dcMem.TextOut(30,210,"6.12");
dcMem.TextOut(30,160,"11.02");
dcMem.TextOut(30,110,"15.92");
dcMem.TextOut(30,65,"20.82");
dcMem.TextOut(30,15,"25.11");
dcMem.SelectObject(pOldFont);
font.DeleteObject();
}
// 绘制Y轴箭头
dcMem.MoveTo(m_right-5,m_bottom-5);
dcMem.LineTo(m_right,m_bottom);
dcMem.LineTo(m_right-5,m_bottom+5);
// 绘制X轴箭头
dcMem.MoveTo(m_left-5,m_top+5);
dcMem.LineTo(m_left,m_top);
dcMem.LineTo(m_left+5,m_top+5);
dcMem.SelectObject(pOldPen);
{
CHAR *str=NULL;
CString strpath=pDoc->GetPathName();
float m_max=0;
float x=m_left;
float y=rc.Height();
CFile file(strpath,CFile::modeRead);
int n=0;
do{
CHAR* szText[256]={0};
n=file.Read(szText,sizeof(StockDay));
stock=(StockDay*)szText;
if (m_max<(stock->m_lMaxPrice/10000.0))
{
m_max=(stock->m_lMaxPrice)/10000.0;
}
if (stock->m_lClosePrice>stock->m_lOpenPrice)
{
float y1=y-y*(stock->m_lOpenPrice)/10000.0/m_max;
float x2=x+10;
float y2=y-y*stock->m_lMaxPrice/10000.0/m_max;
float x3=x+5;
float y3=y-y*(stock->m_lMinPrice)/10000.0/m_max;
float x4=x3;
float y4=y-y*stock->m_lClosePrice/10000.0/m_max;
CPoint p1(x,y1);
CPoint p2(x+10,y4);
CRect rect(p1,p2);
dcMem.Rectangle(&rect);
dcMem.FillSolidRect(&rect,RGB(255,0,0));
CPen* pMyPen=new CPen(PS_SOLID,0,RGB(150,0,0));
dcMem.SelectObject(pMyPen);
dcMem.MoveTo(x3,y2);
dcMem.LineTo(x3,y3);
}
if (stock->m_lClosePrice<stock->m_lOpenPrice)
{
float y1=y-y*(stock->m_lClosePrice)/10000.0/m_max;
float x2=x+10;
float y2=y-y*stock->m_lMaxPrice/10000.0/m_max;
float x3=x+5;
float y3=y-y*(stock->m_lMinPrice)/10000.0/m_max;
float x4=x3;
float y4=y-y*stock->m_lOpenPrice/10000.0/m_max;
CPoint p1(x,y1);
CPoint p2(x+10,y4);
CRect rect(p1,p2);
dcMem.Rectangle(&rect);
dcMem.FillSolidRect(&rect,RGB(0,0,200));
CPen* pMyPen=new CPen(PS_SOLID,0,RGB(0,0,200));
dcMem.SelectObject(pMyPen);
dcMem.MoveTo(x3,y2);
dcMem.LineTo(x3,y3);
}
x=x+10;
}while(n!=0);
file.Close();
}
pDC->BitBlt(0, 0, rc.Width(), rc.Height(), &dcMem, 0, 0, SRCCOPY);
dcMem.DeleteDC();
bmp.DeleteObject();
创建的是多文档应用程序,用了拆分窗口,但是当拉动窗口或建立鼠标十字架时后面的图像就会被刷新成白屏,请高手指教。
{
unsigned long m_lDate; //日期
long m_lOpenPrice; //开
long m_lMaxPrice; //高
long m_lMinPrice; //低
long m_lClosePrice; //收
long m_lMoney; //成交金额
unsigned long m_lTotal; //成交量 单位:百股(手)
long m_lNoUse1; //未使用
long m_lNoUse2; //未使用
long m_lNoUse3; //未使用
}StockDay;
void CMidView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code here
StockDay *stock;
CRect rc;
GetClientRect(&rc);
CDC dcMem; //用于缓冲作图的内存DC
CBitmap bmp; //内存中承载临时图象的位图
dcMem.CreateCompatibleDC(pDC); //依附窗口DC创建兼容内存DC
bmp.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());//创建兼容位图
dcMem.SelectObject(&bmp); //将位图选择进内存DC
//按原来背景填充客户区,不然会是黑色
dcMem.FillSolidRect(rc,RGB(0,0,0));
int m_Low = 0;
int m_High = 1024;
int i;
int m_left,m_top,m_right,m_bottom;
int m_Interval = (m_High - m_Low)/10;
if (m_Interval < 1) m_Interval = 1;
m_left = rc.Width() /15;
m_top = rc.top+10;
m_right = rc.right-10;
m_bottom =99*rc.bottom/100;
int m_IntervalPan = (m_right - m_left)/11;
if (m_IntervalPan < 1 ) m_IntervalPan =1;
CPen curPen;
curPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
CPen* pOldPen=dcMem.SelectObject(&curPen);
// 绘制坐标轴
dcMem.MoveTo(m_left,m_top);
// 垂直轴
dcMem.LineTo(m_left,m_bottom);
// 水平轴
dcMem.LineTo(m_right,m_bottom);
dcMem.SelectObject(pOldPen);
// 写X轴刻度值
for (int y=m_bottom+25; y>=0; y-=m_bottom/6)
{
CRect rcc;
dcMem.MoveTo(75, y);
dcMem.LineTo(m_left, y);
dcMem.SetTextColor(RGB(255,0,0));
dcMem.Rectangle(&rcc);
dcMem.FillSolidRect(&rcc,RGB(0,0,0));
//CClientDC dc(this);
CFont font;
font.CreatePointFont(110,"宋体");
CFont *pOldFont=pDC->SelectObject(&font);
dcMem.SetTextColor(RGB(255,0,0));
dcMem.TextOut(30,250,"1.22");
dcMem.TextOut(30,210,"6.12");
dcMem.TextOut(30,160,"11.02");
dcMem.TextOut(30,110,"15.92");
dcMem.TextOut(30,65,"20.82");
dcMem.TextOut(30,15,"25.11");
dcMem.SelectObject(pOldFont);
font.DeleteObject();
}
// 绘制Y轴箭头
dcMem.MoveTo(m_right-5,m_bottom-5);
dcMem.LineTo(m_right,m_bottom);
dcMem.LineTo(m_right-5,m_bottom+5);
// 绘制X轴箭头
dcMem.MoveTo(m_left-5,m_top+5);
dcMem.LineTo(m_left,m_top);
dcMem.LineTo(m_left+5,m_top+5);
dcMem.SelectObject(pOldPen);
{
CHAR *str=NULL;
CString strpath=pDoc->GetPathName();
float m_max=0;
float x=m_left;
float y=rc.Height();
CFile file(strpath,CFile::modeRead);
int n=0;
do{
CHAR* szText[256]={0};
n=file.Read(szText,sizeof(StockDay));
stock=(StockDay*)szText;
if (m_max<(stock->m_lMaxPrice/10000.0))
{
m_max=(stock->m_lMaxPrice)/10000.0;
}
if (stock->m_lClosePrice>stock->m_lOpenPrice)
{
float y1=y-y*(stock->m_lOpenPrice)/10000.0/m_max;
float x2=x+10;
float y2=y-y*stock->m_lMaxPrice/10000.0/m_max;
float x3=x+5;
float y3=y-y*(stock->m_lMinPrice)/10000.0/m_max;
float x4=x3;
float y4=y-y*stock->m_lClosePrice/10000.0/m_max;
CPoint p1(x,y1);
CPoint p2(x+10,y4);
CRect rect(p1,p2);
dcMem.Rectangle(&rect);
dcMem.FillSolidRect(&rect,RGB(255,0,0));
CPen* pMyPen=new CPen(PS_SOLID,0,RGB(150,0,0));
dcMem.SelectObject(pMyPen);
dcMem.MoveTo(x3,y2);
dcMem.LineTo(x3,y3);
}
if (stock->m_lClosePrice<stock->m_lOpenPrice)
{
float y1=y-y*(stock->m_lClosePrice)/10000.0/m_max;
float x2=x+10;
float y2=y-y*stock->m_lMaxPrice/10000.0/m_max;
float x3=x+5;
float y3=y-y*(stock->m_lMinPrice)/10000.0/m_max;
float x4=x3;
float y4=y-y*stock->m_lOpenPrice/10000.0/m_max;
CPoint p1(x,y1);
CPoint p2(x+10,y4);
CRect rect(p1,p2);
dcMem.Rectangle(&rect);
dcMem.FillSolidRect(&rect,RGB(0,0,200));
CPen* pMyPen=new CPen(PS_SOLID,0,RGB(0,0,200));
dcMem.SelectObject(pMyPen);
dcMem.MoveTo(x3,y2);
dcMem.LineTo(x3,y3);
}
x=x+10;
}while(n!=0);
file.Close();
}
pDC->BitBlt(0, 0, rc.Width(), rc.Height(), &dcMem, 0, 0, SRCCOPY);
dcMem.DeleteDC();
bmp.DeleteObject();
创建的是多文档应用程序,用了拆分窗口,但是当拉动窗口或建立鼠标十字架时后面的图像就会被刷新成白屏,请高手指教。
作者: sunflowerfay 发布时间: 2011-12-04
deletedc与deleteobject有点用反了吧。
作者: jennyvenus 发布时间: 2011-12-06
代码太长、、懒得看、、
作者: zq282502532 发布时间: 2011-12-06
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28