求求大神指点,小弟将不胜感激。。
void CMapreadView::OnDraw(CDC* pDC)
{
CMapreadDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rc; // 定义一个矩形区域变量
GetClientRect(rc);
int nWidth = rc.Width();
int nHeight = rc.Height();
CDC MemDC; //首先定义一个显示设备对象
CBitmap MemBitmap;//定义一个位图对象
MemDC.CreateCompatibleDC(pDC);
MemBitmap.CreateCompatibleBitmap(pDC,nWidth,nHeight);
CBitmap *pOldBit=NULL;
pOldBit=MemDC.SelectObject(&MemBitmap);
MemDC.FillSolidRect(rc.left,rc.top,nWidth,nHeight,RGB(255,255,255));
if (pDoc->m_ifread) pDoc->p_Map.DrawMap(&MemDC); pDC->BitBlt(rc.left,rc.top,nWidth,nHeight,&MemDC,rc.left,rc.top,SRCCOPY);
//绘图完成后的清理
MemDC.SelectObject(&pOldBit);
MemBitmap.DeleteObject();
MemDC.DeleteDC();
}
void CMapreadView::OnDraw(CDC* pDC)
{
CMapreadDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rc; // 定义一个矩形区域变量
GetClientRect(rc);
int nWidth = rc.Width();
int nHeight = rc.Height();
CDC MemDC; //首先定义一个显示设备对象
CBitmap MemBitmap;//定义一个位图对象
MemDC.CreateCompatibleDC(pDC);
MemBitmap.CreateCompatibleBitmap(pDC,nWidth,nHeight);
CBitmap *pOldBit=NULL;
pOldBit=MemDC.SelectObject(&MemBitmap);
MemDC.FillSolidRect(rc.left,rc.top,nWidth,nHeight,RGB(255,255,255));
if (pDoc->m_ifread) pDoc->p_Map.DrawMap(&MemDC); pDC->BitBlt(rc.left,rc.top,nWidth,nHeight,&MemDC,rc.left,rc.top,SRCCOPY);
//绘图完成后的清理
MemDC.SelectObject(&pOldBit);
MemBitmap.DeleteObject();
MemDC.DeleteDC();
}
pDC->BitBlt(rc.left,rc.top,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
是不是 if (pDoc->m_ifread) 条件没有满足
可以加个else 绘制些其他的东西出来看看
这句如果改成
if (pDoc->m_ifread) pDoc->p_Map.DrawMap(pDC);的话,是可以画出来的,说明不是判断条件的问题今天修改了一下,可以画出来了,屏蔽了PrepareDC的内容,并将OnDraw改成了下面内容,虽然画没问题,但是由于屏蔽了PrepareDC,导致点选面状要素的时候出现了问题,纠结啊,求大神帮忙看看,不胜感激。。=====================
void CMapreadView::OnDraw(CDC* pDC)
{
CMapreadDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//双缓存2
//双缓存
CRect rc; // 定义一个矩形区域变量
GetClientRect(&rc);
int nWidth = rc.Width();
int nHeight = rc.Height();
//随后建立与屏幕显示兼容的内存显示设备
//CDC *ppDC = this->GetDC();
MemDC.CreateCompatibleDC(pDC);
//这时还不能绘图,因为没有地方画 ^_^
//下面建立一个与屏幕显示兼容的位图,至于位图的大小嘛,可以用窗口的大小
MemBitmap.CreateCompatibleBitmap(pDC,nWidth,nHeight);
//将位图选入到内存显示设备中
//只有选入了位图的内存显示设备才有地方绘图,画到指定的位图上
CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap);
// SelectObject (MemDC,MemBitmap);
//先用背景色将位图清除干净,这里我用的是白色作为背景
//你也可以用自己应该用的颜色
MemDC.FillSolidRect(rc.left,rc.top,nWidth,nHeight,RGB(0,0,100)); MemDC.SetMapMode(MM_ISOTROPIC);
/* pDC->SetViewportOrg(500,400);*/
MemDC.SetViewportOrg((rc.left+rc.right)/2,(rc.top+rc.bottom)/2);
/*pDC->SetWindowOrg(0,0);*/
MemDC.SetWindowOrg(pDoc->m_WindowOrgX,pDoc->m_WindowOrgY);
MemDC.SetViewportExt(rc.Width(),-rc.Height());
/*pDC->SetWindowExt(nWidth,nHeight);*/
MemDC.SetWindowExt(int(pDoc->m_MapSize.cx*1.2), int(pDoc->m_MapSize.cy*1.2));
//OnPrepareDC(&MemDC);
//绘图
//MemDC.MoveTo(……);
//MemDC.LineTo(……);
if (pDoc->m_ifread) pDoc->p_Map.DrawMap(&MemDC);
//MemDC.Ellipse(-300,-300,300,300);
MemDC.SelectObject(pOldBit);
//将内存中的图拷贝到屏幕上进行显示
//pDC->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
//pDC->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
CDC NewDC;
NewDC.CreateCompatibleDC(pDC);
NewDC.SelectObject(&MemBitmap);
//OnPrepareDC(&NewDC); pDC->BitBlt(rc.left,rc.top,nWidth,nHeight,&NewDC,0,0,SRCCOPY);
//绘图完成后的清理
//MemDC.SelectObject(&pOldBit);
MemBitmap.DeleteObject();
MemDC.DeleteDC();
}===============
点选要用到PrepareDC,屏蔽以后下面这步不知道该怎么改了
===============
void CMapreadView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMapreadDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CClientDC newmap(this);
OnPrepareDC(&newmap);
if((m_LButton)&&(!m_ptselect))
{
// hcurHand= AfxGetApp()->LoadCursor(IDC_CURSORTRAVEL);
// SetCursor(hcurHand);
m_finalpt=point;
newmap.DPtoLP(&m_finalpt);
int x,y;
x=m_firstpt.x-m_finalpt.x;
y=m_firstpt.y-m_finalpt.y;
pDoc->m_WindowOrgX=pDoc->m_WindowOrgX+x;
pDoc->m_WindowOrgY=pDoc->m_WindowOrgY+y;
//AfxMessageBox("Moved");
//turn=FALSE;
Invalidate();
}
CView::OnMouseMove(nFlags, point);
}