mfc-下面的代码怎么实现双缓存去闪

问题描述

下面的代码怎么实现双缓存去闪

// 画图View.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "画图.h"

#include "画图Doc.h"
#include "画图View.h"
#include "SettingDlg.h"
#include
#ifdef DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE
_;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CView)

BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(IDM_LINE, OnLine)
ON_COMMAND(IDM_RECTANGLE, OnRectangle)
ON_COMMAND(IDM_Circle, OnCircle)
ON_COMMAND(IDM_Random_Line, OnRandomLine)
ON_COMMAND(IDM_POLYGON, OnPolygon)
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_COMMAND(IDM_SET_LINE_STYLE_WIDTH, OnSetLineStyleWidth)
ON_COMMAND(IDM_SET_COLOR, OnSetColor)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
{
// TODO: add construction code here
m_nDrawType=0;
m_ptOrigin=0;
m_nLineStyle=0;
m_nLineWidth=1;
m_ncolor=RGB(255,0,0);
m_dcMetaFile.Create();
no1=0;
no2=0;
no3=0;
no4=0;
no5=0;
k=0;
}

CMyView::~CMyView()
{
}

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CView::PreCreateWindow(cs);

}

/////////////////////////////////////////////////////////////////////////////
// CMyView drawing

void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CClientDC dc(this);
CPen pen(m_nLineStyle,m_nLineWidth,m_color);
CPen* pOldPen = pDC->SelectObject(&pen);
CPoint point1,point2;
int temp=k;
//vector::const_iterator i=v.begin();
if(no1 ||no2 ||no3 ||no4|| no5){
switch(m_nDrawType)
{
case 1:
pDC->MoveTo(pDoc->head);
point1.x=pDoc->head.x+5;
point1.y=pDoc->head.y+5;
point2.x=pDoc->head.x-5;
point2.y=pDoc->head.y-5;
pDC->Ellipse(CRect(point1,point2));
pDC->LineTo(pDoc->tail);
point1.x=pDoc->tail.x+5;
point1.y=pDoc->tail.y+5;
point2.x=pDoc->tail.x-5;
point2.y=pDoc->tail.y-5;
pDC->Ellipse(CRect(point1,point2));
break;
case 2:
point1.x=pDoc->m_Rect.left+5;
point1.y=pDoc->m_Rect.top+5;
point2.x=point1.x-10;
point2.y=point1.y-10;
pDC->Ellipse(CRect(point1,point2));
point1.x=pDoc->m_Rect.right+5;
point2.x=point1.x-10;
pDC->Ellipse(CRect(point1,point2));
point1.x=pDoc->m_Rect.left+5;
point1.y=pDoc->m_Rect.bottom+5;
point2.x=point1.x-10;
point2.y=point1.y-10;
pDC->Ellipse(CRect(point1,point2));
point1.x=pDoc->m_Rect.right+5;
point2.x=point1.x-10;
pDC->Ellipse(CRect(point1,point2));
pDC->Rectangle(pDoc->m_Rect);
break;
case 3:

pDC->Ellipse(pDoc->m_Rect);
break;
case 4:
for(temp=0;temp
{
pDC->MoveTo(pDoc->pointduo[temp]);
point1.x=pDoc->pointduo[temp].x+5;
point1.y=pDoc->pointduo[temp].y+5;
point2.x=pDoc->pointduo[temp].x-5;
point2.y=pDoc->pointduo[temp].y-5;
pDC->Ellipse(CRect(point1,point2));
pDC->LineTo(pDoc->pointduo[temp+1]);
point1.x=pDoc->pointduo[temp+1].x+5;
point1.y=pDoc->pointduo[temp+1].y+5;
point2.x=pDoc->pointduo[temp+1].x-5;
point2.y=pDoc->pointduo[temp+1].y-5;
pDC->Ellipse(CRect(point1,point2));
}
pDC->MoveTo(pDoc->pointduo[temp]);
point1.x=pDoc->pointduo[temp].x+5;
point1.y=pDoc->pointduo[temp].y+5;
point2.x=pDoc->pointduo[temp].x-5;
point2.y=pDoc->pointduo[temp].y-5;
pDC->Ellipse(CRect(point1,point2));
pDC->LineTo(pDoc->tail);
point1.x=pDoc->tail.x+5;
point1.y=pDoc->tail.y+5;
point2.x=pDoc->tail.x-5;
point2.y=pDoc->tail.y-5;
pDC->Ellipse(CRect(point1,point2));
break;
case 5:
for(temp=0;temp
{
pDC->MoveTo(pDoc->pointp[temp]);
point1.x=pDoc->pointp[temp].x+5;
point1.y=pDoc->pointp[temp].y+5;
point2.x=pDoc->pointp[temp].x-5;
point2.y=pDoc->pointp[temp].y-5;
pDC->Ellipse(CRect(point1,point2));
pDC->LineTo(pDoc->pointp[temp+1]);
point1.x=pDoc->pointp[temp+1].x+5;
point1.y=pDoc->pointp[temp+1].y+5;
point2.x=pDoc->pointp[temp+1].x-5;
point2.y=pDoc->pointp[temp+1].y-5;
pDC->Ellipse(CRect(point1,point2));
}
pDC->MoveTo(pDoc->pointp[temp]);
point1.x=pDoc->pointp[temp].x+5;
point1.y=pDoc->pointp[temp].y+5;
point2.x=pDoc->pointp[temp].x-5;
point2.y=pDoc->pointp[temp].y-5;
pDC->Ellipse(CRect(point1,point2));
pDC->LineTo(pDoc->tail);
point1.x=pDoc->tail.x+5;
point1.y=pDoc->tail.y+5;
point2.x=pDoc->tail.x-5;
point2.y=pDoc->tail.y-5;
pDC->Ellipse(CRect(point1,point2));
pDC->MoveTo(pDoc->tail);
point1.x=pDoc->tail.x+5;
point1.y=pDoc->tail.y+5;
point2.x=pDoc->tail.x-5;
point2.y=pDoc->tail.y-5;
pDC->Ellipse(CRect(point1,point2));
pDC->LineTo(pDoc->pointp[0]);
point1.x=pDoc->pointp[0].x+5;
point1.y=pDoc->pointp[0].y+5;
point2.x=pDoc->pointp[0].x-5;
point2.y=pDoc->pointp[0].y-5;
pDC->Ellipse(CRect(point1,point2));
}
}
}

/////////////////////////////////////////////////////////////////////////////
// CMyView printing

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

//DEL void CMyView::OnUpdateLine(CCmdUI* pCmdUI)
//DEL {
//DEL // TODO: Add your command update UI handler code here
//DEL

//DEL }

void CMyView::OnLine()
{
// TODO: Add your command handler code here
m_nDrawType=1;
}

void CMyView::OnRectangle()
{
// TODO: Add your command handler code here
m_nDrawType=2;
}

void CMyView::OnCircle()
{
// TODO: Add your command handler code here
m_nDrawType=3;
}

void CMyView::OnRandomLine()
{
// TODO: Add your command handler code here
m_nDrawType=4;
}

void CMyView::OnPolygon()
{
// TODO: Add your command handler code here
m_nDrawType=5;
}

void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
CView::OnLButtonUp(nFlags, point);
}

void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPoint point1,point2;
m_ptOrigin=point;
CMyDoc* pDoc = GetDocument();
if(m_nDrawType==4)
{
pDoc->pointduo[k]=point;
k++;
}
if(m_nDrawType==5)
{
pDoc->pointp[k]=point;
k++;
}
if(no1||no2||no3)
{
switch(m_nDrawType)
{
case 1:if(no1==1)no1=0;break;
case 2:if(no2==1)no2=0;break;
case 3:if(no3==1)no3=0;break;
}
}
else if(m_nDrawType!=0)
{
if(m_nDrawType!=3)
{
CPen pen(0,1,m_color);
CPen* pOldPen = dc.SelectObject(&pen);
point1.x=point.x+5;
point1.y=point.y+5;
point2.x=point.x-5;
point2.y=point.y-5;
dc.Ellipse(CRect(point1,point2));
}
switch(m_nDrawType)
{
case 1:no1=1;
break;
case 2:no2=1;
break;
case 3:no3=1;
break;
case 4:no4=1;
break;
case 5:no5=1;
break;
}
}
CView::OnLButtonDown(nFlags, point);
}

void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CPoint m_ptEnd=point;
CPoint point1,point2,point3,point4;
CMyDoc* pDoc = GetDocument();
CClientDC dc(this);
switch(m_nDrawType)
{
case 1:
pDoc->head=m_ptOrigin;
pDoc->tail=m_ptEnd;
if(no1) Invalidate();
break;
case 2:case 3:
pDoc->m_Rect.left=m_ptOrigin.x;
pDoc->m_Rect.top=m_ptOrigin.y;
pDoc->m_Rect.right=m_ptEnd.x;
pDoc->m_Rect.bottom=m_ptEnd.y;
if(no2 || no3) Invalidate();
case 4:case 5:
pDoc->tail=m_ptEnd;
if(no5 || no4) Invalidate();
break;
}

CView::OnMouseMove(nFlags, point);

}

void CMyView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

CView::OnRButtonDown(nFlags, point);

}

void CMyView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_nDrawType==4)
{
no4=0;
k=0;
}
if(m_nDrawType==5)
{
no5=0;
k=0;
}
CView::OnRButtonUp(nFlags, point);
}

void CMyView::OnSetLineStyleWidth()
{
// TODO: Add your command handler code here

CSettingDlg dlg;
//dlg.DoModal();
dlg.m_nLineWidth=m_nLineWidth;
dlg.m_nLineStyle=m_nLineStyle;
if(IDOK==dlg.DoModal())
{
    m_nLineWidth=dlg.m_nLineWidth ;
    m_nLineStyle=dlg.m_nLineStyle ;
}

}

void CMyView::OnSetColor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
dlg.m_cc.Flags |=CC_RGBINIT | CC_FULLOPEN;
dlg.m_cc.rgbResult=m_color;
if(IDOK==dlg.DoModal())
{
m_color=dlg.m_cc.rgbResult;
}
}

时间: 2024-09-17 03:52:02

mfc-下面的代码怎么实现双缓存去闪的相关文章

mfc 双缓存-MFC 双缓存 贴图png问题

问题描述 MFC 双缓存 贴图png问题 最近在做一个图片编辑的软件,我用的图资源为png图,使用了CImage类来显示图片,在使用双缓存的时候,显示的图片颜色不对,在网上找了很多资源都是说GDI不支持透明色,需要使用GDI+,不太清楚GDI+怎么实现双缓存?

VC图形绘制双缓存的代码复用性讨论

在前文中已经讨论了如何实现界面绘制双缓存的问题,前文网址如下: http://www.2cto.com/kf/201111/112429.html   双缓存的主要思路是:先把图形绘制到内存DC中,然后再把内存DC中的所有图形一次性的复制到屏幕DC中.在前文的实现示例中,我们把直接往DC中绘制图形的函数封装为DrawDirect,把通过双缓存来实现图形绘制的函数封装为DrawWithBufferEfficient,其中DrawWithBufferEfficient调用了DrawDirect函数.

mm_loenglish模式-MFC CScrollView 映射模式为MM_LOENGLISH 双缓冲

问题描述 MFC CScrollView 映射模式为MM_LOENGLISH 双缓冲 我想在MFC中应用双缓存技术来消除闪烁,代码如下(为了测试,先只画了一条直线):void CDblBufTestView::OnDraw(CDC* pDC){ CDC dcMem; dcMem.CreateCompatibleDC(pDC); //创建与视图的设备相兼容的内存设备 CBitmap bmp; bmp.CreateCompatibleBitmap(pDCrect.rightrect.bottom);

C#的双缓存技术

缓存 protected override void OnPaint(PaintEventArgs e)  {    System.Drawing.Bitmap b = new Bitmap(this.Width,this.Height);//双缓冲技术,先将所有要画的画在该图片中,再调用GS画出该图片.   Graphics g = Graphics.FromImage((System.Drawing.Image)b);   // 在这里画你所需要画的 //   e.Graphics.Draw

Symbian编程总结-图形图像篇-使用双缓存进行图形的绘制

所谓"双缓冲",指的是在绘图时并不是直接绘到屏幕上,而是在内存中开辟一个缓冲区,在这个缓冲区里完成所有的绘图后,直接将其"粘贴"到屏幕上.采用双缓冲技术,由于绘图操作大部分在内存中完成,所以绘图速度没有太大的制约:此外,当进行复杂的绘图操作时,使用双缓冲技术可以有效的防止画面的闪烁. 一.双缓存技术在J2ME中的实现 在J2ME中,实现双缓存绘制图形可以通过以下步骤实现: 首先创建一个类成员变量Image对象,此Image对象的图像尺寸为屏幕尺寸大小. 如:如果屏幕

Android优化双缓存的图片异步加载工具(LruCache+SoftReference)

之前在郭大神的博客看到使用LruCache算法实现图片缓存的.这里仿效他的思路,自己也写了一个. 并加入ConcurrentHashMap<String, SoftReference<Bitmap>>去实现二级缓存,因为ConcurrentHashMap是多个锁的线程安全,支持高并发.很适合这种频繁访问读取内存的操作. 下面整个思路是,使用了系统提供的LruCache类做一级缓存, 大小为运行内存的1/8,当LruCache容量要满的时候,会自动将系统移除的图片放到二级缓存中,但为

mfc-请教一下VC++MFC一段代码的意思

问题描述 请教一下VC++MFC一段代码的意思 在鼠标右键菜单ONCONTEXTMENU函数里面,有这么一段 CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_TYPING_TEST_VIEW)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS

共享内存-高效的双缓存任务队列实现

问题描述 高效的双缓存任务队列实现 我这里有一个共享内存实现的队列,出队和入队会有加锁和解锁的情况,这样效率不高,我想实现一个爽缓存共享内存队列,把读和写分离,大侠们是否能提供的思路! 解决方案 http://www.cnblogs.com/csuchao/archive/2012/03/20/2409049.html 解决方案二: http://blog.csdn.net/morewindows/article/details/8646902 上面这个大牛还写了一个专栏,我觉的这个比较清晰 解

canvas-android 如何利用双缓存将缓存区域的某张图复制其中的某一部分到画布上?

问题描述 android 如何利用双缓存将缓存区域的某张图复制其中的某一部分到画布上? android 如何利用双缓存将缓存区域的某张图复制其中的某一部分到画布上.求各路大侠指导,不胜感激!!!