第一次画出来时lpbuf中没有存入数据,刷新一次就有数据了,怎么回事?在内存DC上画图到底改变了什么?能直接把数据传给Hbitmap,或者lpbuf吗?
void CMyDrawView::OnDraw(CDC* pDC)
{
CMyDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
HBITMAP oldbitmap;
CDC memDc;
int i, nMaxNum = 0;
int ntleftx, nttopy, nleftx, ntopy, ntrightx, ntbottomy, nrightx, nbottomy, nwidth, nheight;
ntrightx = ntbottomy = nrightx =nbottomy = nwidth = nheight = 0;
ntleftx = nttopy = nleftx = ntopy = 2147483647;
if(pDoc->m_hbitmap == NULL)
return;
memDc.CreateCompatibleDC(pDC);
oldbitmap = (HBITMAP)memDc.SelectObject(pDoc->m_hbitmap);
if(pDoc->m_iDrawType != 0 )
{
for(i = 0; i < m_ptrarray.GetSize(); i++)
{
CPen pen;
CBrush Brush;
pen.CreatePen(PS_SOLID,2,((CGraph*)m_ptrarray.GetAt(i))->m_color);
Brush.CreateSolidBrush(((CGraph*)m_ptrarray.GetAt(i))->m_color);
memDc.SelectObject(&pen);
memDc.SelectObject(&Brush);
switch(((CGraph*)m_ptrarray.GetAt(i))->m_iDrawType)
{
case DRAW_LINE:
memDc.MoveTo(((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.y);
memDc.LineTo(((CGraph*)m_ptrarray.GetAt(i))->m_ptend.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptend.y);
break;
case DRAW_RECTANGLE:
memDc.Rectangle(((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.y,
((CGraph*)m_ptrarray.GetAt(i))->m_ptend.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptend.y);
break;
case DRAW_ELLIPSE:
memDc.Ellipse(((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.y,
((CGraph*)m_ptrarray.GetAt(i))->m_ptend.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptend.y);
break;
default:
break;
}
}
}
StretchBlt(pDC->GetSafeHdc(), 0, 0, pDoc->m_nwidth*pDoc->m_iZoomFactor/100,
pDoc->m_nheight*pDoc->m_iZoomFactor/100, memDc.GetSafeHdc(), 0, 0,
pDoc->m_nwidth, pDoc->m_nheight, SRCCOPY);
if(pDoc->m_nwidth > 0 && pDoc->m_nheight > 0 && pDoc->m_hbitmap != NULL)
{
SetScrollSizes(MM_TEXT ,CSize(pDoc->m_nwidth*pDoc->m_iZoomFactor/100,
pDoc->m_nheight*pDoc->m_iZoomFactor/100));
}
memDc.SelectObject(oldbitmap);
memDc.DeleteDC();
}
void CMyDrawView::OnDraw(CDC* pDC)
{
CMyDrawDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
HBITMAP oldbitmap;
CDC memDc;
int i, nMaxNum = 0;
int ntleftx, nttopy, nleftx, ntopy, ntrightx, ntbottomy, nrightx, nbottomy, nwidth, nheight;
ntrightx = ntbottomy = nrightx =nbottomy = nwidth = nheight = 0;
ntleftx = nttopy = nleftx = ntopy = 2147483647;
if(pDoc->m_hbitmap == NULL)
return;
memDc.CreateCompatibleDC(pDC);
oldbitmap = (HBITMAP)memDc.SelectObject(pDoc->m_hbitmap);
if(pDoc->m_iDrawType != 0 )
{
for(i = 0; i < m_ptrarray.GetSize(); i++)
{
CPen pen;
CBrush Brush;
pen.CreatePen(PS_SOLID,2,((CGraph*)m_ptrarray.GetAt(i))->m_color);
Brush.CreateSolidBrush(((CGraph*)m_ptrarray.GetAt(i))->m_color);
memDc.SelectObject(&pen);
memDc.SelectObject(&Brush);
switch(((CGraph*)m_ptrarray.GetAt(i))->m_iDrawType)
{
case DRAW_LINE:
memDc.MoveTo(((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.y);
memDc.LineTo(((CGraph*)m_ptrarray.GetAt(i))->m_ptend.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptend.y);
break;
case DRAW_RECTANGLE:
memDc.Rectangle(((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.y,
((CGraph*)m_ptrarray.GetAt(i))->m_ptend.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptend.y);
break;
case DRAW_ELLIPSE:
memDc.Ellipse(((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptbegin.y,
((CGraph*)m_ptrarray.GetAt(i))->m_ptend.x, ((CGraph*)m_ptrarray.GetAt(i))->m_ptend.y);
break;
default:
break;
}
}
}
StretchBlt(pDC->GetSafeHdc(), 0, 0, pDoc->m_nwidth*pDoc->m_iZoomFactor/100,
pDoc->m_nheight*pDoc->m_iZoomFactor/100, memDc.GetSafeHdc(), 0, 0,
pDoc->m_nwidth, pDoc->m_nheight, SRCCOPY);
if(pDoc->m_nwidth > 0 && pDoc->m_nheight > 0 && pDoc->m_hbitmap != NULL)
{
SetScrollSizes(MM_TEXT ,CSize(pDoc->m_nwidth*pDoc->m_iZoomFactor/100,
pDoc->m_nheight*pDoc->m_iZoomFactor/100));
}
memDc.SelectObject(oldbitmap);
memDc.DeleteDC();
}
解决方案 »
- WIN32API中,按下字母键为什么得到的WM_KEYDOWN消息wParam参数都是大写?
- MFC中的小小问题,求教!
- 如何让工具栏的按钮变成圆角矩形?
- udp 编程
- 给控件载入图片
- CreateService与字符串,怪异至极,大侠高手看过来!!
- VC代码的字体只有那么几个难看的,有什么插件能使它用别的字体吗?
- SOCKET编程中如何能知道即时的SOCKET状态和连接是否在正常呢(也就是突然掉线的那种情况)?
- 在单文档多窗口的程序中如何在一个视图类中调用另一个视图类的函数
- 一个关于创建进程的问题:
- 下列语句一直联不上数据库,不知怎么回事!
- [200分]想去北京找工作 请问在要在哪个网站上注册简历比较好??
VOID Example_DrawCachedBitmap(HDC hdc)
{
Graphics graphics(hdc);// Create Bitmap object.
Bitmap bitmap(L"Climber.jpg");// Use the Bitmap object to create a CachedBitmap object.
CachedBitmap cachedBitmap(&bitmap, &graphics);// Draw the cached bitmap.
graphics.DrawCachedBitmap(&cachedBitmap, 20, 10);
}