CDC
int m_nmx;
int m_nmy;
CBitmap *m_pbmp;
CDC *m_pmdc; 为全局变量
int CMy1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_nmx=GetSystemMetrics(SM_CXSCREEN);
m_nmy=GetSystemMetrics(SM_CXSCREEN);
CDC *pDC=GetDC();
m_pmdc->CreateCompatibleDC(pDC);
m_pbmp->CreateCompatibleBitmap(pDC,m_nmx,m_nmy);//与显示设备相兼容的位图
CBitmap *pOldBitmap=m_pmdc->SelectObject(m_pbmp);//将位图选入设备环境;并保留原位图
CBrush brush;
brush.CreateStockObject(WHITE_BRUSH);
CRect rect(-1,-1,m_nmx,m_nmy);
m_pmdc->FillRect( rect,&brush);
m_pmdc->SelectObject(pOldBitmap);
ReleaseDC(pDC);
}
m_pmdc->CreateCompatibleDC(pDC);
m_pbmp->CreateCompatibleBitmap(pDC,m_nmx,m_nmy);//与显示设备相兼容的位图
这两行显示有错误;为何??????????
[解决办法]
编译错?连接错?运行时有问题?
隐约记得描画一类的操作不能放在OnCreate这样的地方,否则不正常,要更晚一点的时点,比如OnInitDialog,具体记不清了= =
[解决办法]
应该是运行时崩溃吧
dc是attach到某个窗口的,现在窗口还没创建好,dc当然不能用了
[解决办法]
m_pmdc和m_pmdc都是空指针啊,要先new一下才能用