怎样做才能在画直线时,只刷新直线,而不刷新背景(因为位图很大,刷新会狂闪,也没有必要)。在线等!
11 个解决方案
#1
异或方式画线
#2
CDrawLineView::CDrawLineView()
{
// TODO: add construction code here
dCount=0;
}
enum {ppoint,line,bline,pline,circle,rectangle,muli,text,pic} DStatus=line;
#include <comdef.h>
void CDrawLineView::OnDraw(CDC* pDC)
{
CDrawLineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int j=4;
int *a=NULL;
a=&j;
j=5;
a=(int*)malloc(sizeof(int));
*a=2;
free(a);
a=new int;
*a=3;
delete a;
}
void CDrawLineView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
dCount=dCount+1;
CClientDC dc(this);
if (DStatus==line)
{
if (dCount==2)
{
dCount=0;
DlPoint=false;
}
else if (dCount==1)
{
s_Point=point;
DlPoint=true;
}
else
{
DlPoint=false;
}
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CDrawLineView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
CPoint myPoint;
CClientDC dc(this);
this->OnPrepareDC(&dc);
if (dCount==1)
{
if (DStatus==line)
{
DrawLine(&dc,s_Point,point);
if (DlPoint==false)
DrawLine(&dc,s_Point,fpoint);
}
fpoint=point;
DlPoint=false;
}
CScrollView::OnMouseMove(nFlags, point);
}
void CDrawLineView::DrawLine(CDC *pDC, CPoint sp, CPoint tp)
{
CPen m_pen;
pDC->SetROP2(R2_NOTXORPEN);
m_pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
CPen* pen=(CPen*)pDC->SelectObject(&m_pen);
COLORREF OldColor=pDC->SetBkColor(pDC->GetBkColor());
int OldBkMode=pDC->SetBkMode(TRANSPARENT);
pDC->MoveTo(sp);
pDC->LineTo(tp);
pDC->SelectObject(pen);
pDC->SetBkMode(OldBkMode);
pDC->SetBkColor(OldColor);
}
{
// TODO: add construction code here
dCount=0;
}
enum {ppoint,line,bline,pline,circle,rectangle,muli,text,pic} DStatus=line;
#include <comdef.h>
void CDrawLineView::OnDraw(CDC* pDC)
{
CDrawLineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int j=4;
int *a=NULL;
a=&j;
j=5;
a=(int*)malloc(sizeof(int));
*a=2;
free(a);
a=new int;
*a=3;
delete a;
}
void CDrawLineView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
dCount=dCount+1;
CClientDC dc(this);
if (DStatus==line)
{
if (dCount==2)
{
dCount=0;
DlPoint=false;
}
else if (dCount==1)
{
s_Point=point;
DlPoint=true;
}
else
{
DlPoint=false;
}
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CDrawLineView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
CPoint myPoint;
CClientDC dc(this);
this->OnPrepareDC(&dc);
if (dCount==1)
{
if (DStatus==line)
{
DrawLine(&dc,s_Point,point);
if (DlPoint==false)
DrawLine(&dc,s_Point,fpoint);
}
fpoint=point;
DlPoint=false;
}
CScrollView::OnMouseMove(nFlags, point);
}
void CDrawLineView::DrawLine(CDC *pDC, CPoint sp, CPoint tp)
{
CPen m_pen;
pDC->SetROP2(R2_NOTXORPEN);
m_pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
CPen* pen=(CPen*)pDC->SelectObject(&m_pen);
COLORREF OldColor=pDC->SetBkColor(pDC->GetBkColor());
int OldBkMode=pDC->SetBkMode(TRANSPARENT);
pDC->MoveTo(sp);
pDC->LineTo(tp);
pDC->SelectObject(pen);
pDC->SetBkMode(OldBkMode);
pDC->SetBkColor(OldColor);
}
#3
同意用异或方式。
其它方法还有双缓存的方式,在内存设备中先画好。
其它方法还有双缓存的方式,在内存设备中先画好。
#4
请问二楼,怎样用双缓存方式,能否具体一点,谢谢先!
#5
请问二楼,怎样用双缓存方式,能否具体一点,谢谢先!
#6
/*****************************************/
CRect rect;
this->GetClientRect(&rect);
//内存绘图
CBitmap* pOldBmp = NULL;
MemDC.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC,lWidth,lHeight);
MemDC.SelectObject(&memBitmap);
MemDC.BitBlt(0,0,lWidth,lHeight,pDC,0,0,SRCCOPY);
pDib->Draw(MemDC.m_hDC, 0, 0, lWidth, lHeight,
0, 0, lWidth, lHeight, DIB_RGB_COLORS, SRCCOPY);
pDC->BitBlt(0,0,lWidth,lHeight,&MemDC,0,0,SRCCOPY);
MemDC.DeleteDC();
memBitmap.DeleteObject();//双缓存显示DIB位图
CRect rect;
this->GetClientRect(&rect);
//内存绘图
CBitmap* pOldBmp = NULL;
MemDC.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC,lWidth,lHeight);
MemDC.SelectObject(&memBitmap);
MemDC.BitBlt(0,0,lWidth,lHeight,pDC,0,0,SRCCOPY);
pDib->Draw(MemDC.m_hDC, 0, 0, lWidth, lHeight,
0, 0, lWidth, lHeight, DIB_RGB_COLORS, SRCCOPY);
pDC->BitBlt(0,0,lWidth,lHeight,&MemDC,0,0,SRCCOPY);
MemDC.DeleteDC();
memBitmap.DeleteObject();//双缓存显示DIB位图
#7
明天看
#8
我试过双缓冲根本不管用,该闪还是闪,就是没有那么严重而已
#9
楼上和楼主是一个人?
#10
双缓冲最后都是贴的位图到屏幕上,一般不会闪烁了,或许是你处理得不正确.
譬如内存缓冲里对背景的处理不寻,或是激发了非双缓冲的onpaint导致刷屏或非双缓冲的刷背景
譬如内存缓冲里对背景的处理不寻,或是激发了非双缓冲的onpaint导致刷屏或非双缓冲的刷背景
#11
用异或,画出来的线还是纯色的吗?不变成花花绿绿的了?
#1
异或方式画线
#2
CDrawLineView::CDrawLineView()
{
// TODO: add construction code here
dCount=0;
}
enum {ppoint,line,bline,pline,circle,rectangle,muli,text,pic} DStatus=line;
#include <comdef.h>
void CDrawLineView::OnDraw(CDC* pDC)
{
CDrawLineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int j=4;
int *a=NULL;
a=&j;
j=5;
a=(int*)malloc(sizeof(int));
*a=2;
free(a);
a=new int;
*a=3;
delete a;
}
void CDrawLineView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
dCount=dCount+1;
CClientDC dc(this);
if (DStatus==line)
{
if (dCount==2)
{
dCount=0;
DlPoint=false;
}
else if (dCount==1)
{
s_Point=point;
DlPoint=true;
}
else
{
DlPoint=false;
}
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CDrawLineView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
CPoint myPoint;
CClientDC dc(this);
this->OnPrepareDC(&dc);
if (dCount==1)
{
if (DStatus==line)
{
DrawLine(&dc,s_Point,point);
if (DlPoint==false)
DrawLine(&dc,s_Point,fpoint);
}
fpoint=point;
DlPoint=false;
}
CScrollView::OnMouseMove(nFlags, point);
}
void CDrawLineView::DrawLine(CDC *pDC, CPoint sp, CPoint tp)
{
CPen m_pen;
pDC->SetROP2(R2_NOTXORPEN);
m_pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
CPen* pen=(CPen*)pDC->SelectObject(&m_pen);
COLORREF OldColor=pDC->SetBkColor(pDC->GetBkColor());
int OldBkMode=pDC->SetBkMode(TRANSPARENT);
pDC->MoveTo(sp);
pDC->LineTo(tp);
pDC->SelectObject(pen);
pDC->SetBkMode(OldBkMode);
pDC->SetBkColor(OldColor);
}
{
// TODO: add construction code here
dCount=0;
}
enum {ppoint,line,bline,pline,circle,rectangle,muli,text,pic} DStatus=line;
#include <comdef.h>
void CDrawLineView::OnDraw(CDC* pDC)
{
CDrawLineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int j=4;
int *a=NULL;
a=&j;
j=5;
a=(int*)malloc(sizeof(int));
*a=2;
free(a);
a=new int;
*a=3;
delete a;
}
void CDrawLineView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
dCount=dCount+1;
CClientDC dc(this);
if (DStatus==line)
{
if (dCount==2)
{
dCount=0;
DlPoint=false;
}
else if (dCount==1)
{
s_Point=point;
DlPoint=true;
}
else
{
DlPoint=false;
}
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CDrawLineView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
CPoint myPoint;
CClientDC dc(this);
this->OnPrepareDC(&dc);
if (dCount==1)
{
if (DStatus==line)
{
DrawLine(&dc,s_Point,point);
if (DlPoint==false)
DrawLine(&dc,s_Point,fpoint);
}
fpoint=point;
DlPoint=false;
}
CScrollView::OnMouseMove(nFlags, point);
}
void CDrawLineView::DrawLine(CDC *pDC, CPoint sp, CPoint tp)
{
CPen m_pen;
pDC->SetROP2(R2_NOTXORPEN);
m_pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
CPen* pen=(CPen*)pDC->SelectObject(&m_pen);
COLORREF OldColor=pDC->SetBkColor(pDC->GetBkColor());
int OldBkMode=pDC->SetBkMode(TRANSPARENT);
pDC->MoveTo(sp);
pDC->LineTo(tp);
pDC->SelectObject(pen);
pDC->SetBkMode(OldBkMode);
pDC->SetBkColor(OldColor);
}
#3
同意用异或方式。
其它方法还有双缓存的方式,在内存设备中先画好。
其它方法还有双缓存的方式,在内存设备中先画好。
#4
请问二楼,怎样用双缓存方式,能否具体一点,谢谢先!
#5
请问二楼,怎样用双缓存方式,能否具体一点,谢谢先!
#6
/*****************************************/
CRect rect;
this->GetClientRect(&rect);
//内存绘图
CBitmap* pOldBmp = NULL;
MemDC.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC,lWidth,lHeight);
MemDC.SelectObject(&memBitmap);
MemDC.BitBlt(0,0,lWidth,lHeight,pDC,0,0,SRCCOPY);
pDib->Draw(MemDC.m_hDC, 0, 0, lWidth, lHeight,
0, 0, lWidth, lHeight, DIB_RGB_COLORS, SRCCOPY);
pDC->BitBlt(0,0,lWidth,lHeight,&MemDC,0,0,SRCCOPY);
MemDC.DeleteDC();
memBitmap.DeleteObject();//双缓存显示DIB位图
CRect rect;
this->GetClientRect(&rect);
//内存绘图
CBitmap* pOldBmp = NULL;
MemDC.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC,lWidth,lHeight);
MemDC.SelectObject(&memBitmap);
MemDC.BitBlt(0,0,lWidth,lHeight,pDC,0,0,SRCCOPY);
pDib->Draw(MemDC.m_hDC, 0, 0, lWidth, lHeight,
0, 0, lWidth, lHeight, DIB_RGB_COLORS, SRCCOPY);
pDC->BitBlt(0,0,lWidth,lHeight,&MemDC,0,0,SRCCOPY);
MemDC.DeleteDC();
memBitmap.DeleteObject();//双缓存显示DIB位图
#7
明天看
#8
我试过双缓冲根本不管用,该闪还是闪,就是没有那么严重而已
#9
楼上和楼主是一个人?
#10
双缓冲最后都是贴的位图到屏幕上,一般不会闪烁了,或许是你处理得不正确.
譬如内存缓冲里对背景的处理不寻,或是激发了非双缓冲的onpaint导致刷屏或非双缓冲的刷背景
譬如内存缓冲里对背景的处理不寻,或是激发了非双缓冲的onpaint导致刷屏或非双缓冲的刷背景
#11
用异或,画出来的线还是纯色的吗?不变成花花绿绿的了?