| 发表于:2007-09-20 14:15:27 楼主 |
我在内存中画图,一个用来画曲线,一个画坐标 程序如下 画曲线,这里实际画出了三条曲线: getclientrect(&rectclient); cpen newpen(ps_solid,1.5,rgb(251,0,250)); cpen newpenblock(ps_solid,1.3,rgb(111,111,111)); cpen newpensample(ps_solid,1.3,rgb(100,200,150)); poldpen = m_tmpdc.selectobject(&newpen); m_tmpdc.moveto(y-1,220-2*lidtold); m_tmpdc.lineto(y,220-2*date[0]); m_tmpdc.selectobject(poldpen); poldpenblock = m_tmpdc.selectobject(&newpenblock); m_tmpdc.moveto(y-1, 220-2*blocktold); m_tmpdc.lineto(y, 220-2*date[1]); m_tmpdc.selectobject(poldpenblock); poldpensample =m_tmpdc.selectobject(&newpensample); m_tmpdc.moveto(y-1, 220-2*calctold); m_tmpdc.lineto(y, 220-2*date[2]); m_tmpdc.selectobject(poldpensample); lidtold=date[0];//保存老的数据做下一次画线的起点 blocktold=date[1]; calctold=date[2]; y++; m_tmpdcsample.selectobject(poldpensample); //将m_tmpdc内容绘制到m_olddc上 m_olddc.bitblt(0, 0, rectclient.width(), rectclient.height(), &m_tmpdc, 0, 0, srccopy) ; m_tmpdc.bitblt(0, 0, rectclient.width(), rectclient.height(), &m_tmpdcblock, 0, 0, srcpaint) ; //将m_tmpdcblock内容绘制到m_olddc上 rectclient.height(), rectclient.height(), ; //删除画笔gdi对象 newpen.deleteobject(); newpenblock.deleteobject(); newpensample.deleteobject(); //触发窗体重画 if(printgraph> 5000) printgraph=0; invalidate(); 画坐标及初始化设备函数: void main::invalidatectrl() { crect rectclient; getclientrect(rectclient); cclientdc dc(getdlgitem(idc_staticq));//定义控件设备,把内存的图拷贝到控件上显示 cbrush brushback(rgb(255,255,255)); cpaintdc dc(this);//定义窗口设备,虽然在控件上画图但一定也要定义窗口设备,不然窗口不可见 if (m_tmpdc.getsafehdc() == null) { m_tmpdc.createcompatibledc(&dc); m_tmpbmp.createcompatiblebitmap(&dc,rectclient.width(),rectclient.height()); m_tmpdc.selectobject(&m_tmpbmp); } //设置背景颜色 m_tmpdc.setbkcolor(rgb(255,255,255)); m_tmpdc.fillrect(rectclient,&brushback); if (m_tmpdcblock.getsafehdc() == null) { m_tmpdcblock.createcompatibledc(&dc) ; m_tmpbmpblock.createcompatiblebitmap(&dc, rectclient.width(), rectclient.height()) ; m_tmpdcblock.selectobject(&m_tmpbmpblock) ; } m_tmpdcblock.setbkcolor (rgb(255,255,255)) ; m_tmpdcblock.fillrect(rectclient, &brushback) ; cpen newpen(ps_solid,1.5,rgb(125,0,250)); cstring emp; poldpen = m_tmpdcblock.selectobject(&newpen); m_tmpdcblock.moveto(22, 5); m_tmpdcblock.lineto(22, 210); m_tmpdcblock.lineto(622, 210); for(int i=1;i <=10;i++) { m_tmpdcblock.moveto(22, 20*i-5); m_tmpdcblock.lineto(27,20*i-5); emp.format(_t( "%d "),i*10); m_tmpdcblock.exttextout(1,210-20*i,eto_clipped,null,emp,wcslen(emp),null); } for(int j=1;j <=10;j++) { m_tmpdcblock.moveto(22+60*j, 210); m_tmpdcblock.lineto(22+60*j,205); emp.format(_t( "%d "),j*2); emp=emp+ " "+ "m "; m_tmpdcblock.exttextout(10+60*j,211,eto_clipped,null,emp,wcslen(emp),null); } m_tmpdcblock.selectobject(poldpen ); newpen.deleteobject(); } 下面是onpaint() void main::onpaint() { cpaintdc dc(this);//定义窗口设备,虽然在控件上画图但一定也要定义窗口设备,不然窗口不可见 // device context for painting, cclientdc dc(getdlgitem(idc_staticq));//定义控件设备,把内存的图拷贝到控件上显示 // todo: add your message handler code here crect rectclient; getclientrect(rectclient); cdc memdc ; cbitmap membitmap ; cbitmap* oldbitmap ; memdc.createcompatibledc(&dc); membitmap.createcompatiblebitmap(&dc, rectclient.width(), rectclient.height()) ; oldbitmap = (cbitmap *)memdc.selectobject(&membitmap) ; if(memdc.getsafehdc()!=null) { memdc.bitblt(0,0,rectclient.width(),rectclient.height(),&m_tmpdc,0,0,srccopy); memdc.bitblt(0,0,rectclient.width(),rectclient.height(),&m_tmpdcblock,0,0,srcpaint); dc.bitblt(0,0,rectclient.width(),rectclient.height(),&memdc,0,0,srccopy); // do not call cformview::onpaint() for painting messages } memdc.selectobject(oldbitmap) ; //删除内存位图gdi对象 membitmap.deleteobject(); //删除内存绘图环境 memdc.deletedc(); } 问题:我不能画出图形,再数分钟后能看见一条隔很长时间画出一小段曲线,后面又是空白,再等很长时间再画一小段,又出现空白,并看不到坐标 1.然我在onpaint() 这里用这两句 memdc.bitblt(0,0,rectclient.width(),rectclient.height(),&m_tmpdc,0,0,srccopy); dc.bitblt(0,0,rectclient.width(),rectclient.height(),&memdc,0,0,srccopy); 画曲线正常显示,不显示坐标 2.我用这两句 memdc.bitblt(0,0,rectclient.width(),rectclient.height(),&m_tmpdcblock,0,0,srcpaint); dc.bitblt(0,0,rectclient.width(),rectclient.height(),&memdc,0,0,srccopy); 能正常显示坐标,请高手帮忙看看 |
|
|
|
|