一个非常奇怪的编程问题
程序一可以正常显示图形,程序二不能显示图形,程序三又可以正常显示图形了,(三个程序均不存在编译和运行问题)这到底是为什么?百思不得其解,请高手执教。叩谢!
class CMemBitmapView : public CView
{
public:
CDC *PDC; //创建屏幕绘图设备指针
CDC memDC; //创建内存绘图设备
CBitmap memBitmap; //创建内存位图
CBitmap* pOldBmp; //创建原始位图指针
CRect rect; //创建矩形,用于保存屏幕窗口坐标
public:
afx_msg void OnHuitu();
public:
afx_msg void OnTimer(UINT_PTR nIDEvent);
};
程序一
void CMemBitmapView::OnHuitu()
{
rect.left=0;
rect.top=0;
rect.right=1024;
rect.bottom=768;
PDC=this->GetDC();
memDC.CreateCompatibleDC(PDC);
memBitmap.CreateCompatibleBitmap(PDC,rect.right,rect.bottom);
pOldBmp = memDC.SelectObject(&memBitmap);
memDC.FillSolidRect(rect,RGB(255,255,255));
memDC.Ellipse(300,150,650,500);
PDC->BitBlt(rect.left,rect.top,rect.right,rect.bottom,&memDC,0,0,SRCCOPY);
}
程序二
void CMemBitmapView::OnHuitu()
{
rect.left=0;
rect.top=0;
rect.right=1024;
rect.bottom=768;
PDC=this->GetDC();
memDC.CreateCompatibleDC(PDC);
memBitmap.CreateCompatibleBitmap(PDC,rect.right,rect.bottom);
pOldBmp = memDC.SelectObject(&memBitmap);
memDC.FillSolidRect(rect,RGB(255,255,255));
CMemBitmapView::SetTimer(1,100,NULL);
}
void CMemBitmapView::OnTimer(UINT_PTR nIDEvent)
{
memDC.Ellipse(300,150,650,500);
PDC->BitBlt(rect.left,rect.top,rect.right,rect.bottom,&memDC,0,0,SRCCOPY);
CView::OnTimer(nIDEvent);
}
程序三
void CMemBitmapView::OnHuitu()
{
rect.left=0;
rect.top=0;
rect.right=1024;
rect.bottom=768;
PDC=this->GetDC();
memDC.CreateCompatibleDC(PDC);
memBitmap.CreateCompatibleBitmap(PDC,rect.right,rect.bottom);
pOldBmp = memDC.SelectObject(&memBitmap);
memDC.FillSolidRect(rect,RGB(255,255,255));
CMemBitmapView::SetTimer(1,100,NULL);
}
void CMemBitmapView::OnTimer(UINT_PTR nIDEvent)
{
PDC=this->GetDC();
memDC.Ellipse(300,150,650,500);
PDC->BitBlt(rect.left,rect.top,rect.right,rect.bottom,&memDC,0,0,SRCCOPY);
CView::OnTimer(nIDEvent);
}