在单文档中加载一幅背景用OnEraseBkgnd(CDC* pDC) 代码如下:
BOOL CProjectView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP2); BITMAP bmp;
bitmap.GetBitmap(&bmp);
CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC); dcCompatible.SelectObject(&bitmap); CRect rect;
GetClientRect(&rect);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,
0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY); return TRUE;}
运行时会弹出一个Debug assertion failed错误消息框,分步调试发现运行到bitmap.GetBitmap(&bmp);时出错的,重新创建的一个新的单文档程序是可以的,但在我在这功能是读串口的单文档里不行为什么啊?
BOOL CProjectView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP2); BITMAP bmp;
bitmap.GetBitmap(&bmp);
CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC); dcCompatible.SelectObject(&bitmap); CRect rect;
GetClientRect(&rect);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,
0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY); return TRUE;}
运行时会弹出一个Debug assertion failed错误消息框,分步调试发现运行到bitmap.GetBitmap(&bmp);时出错的,重新创建的一个新的单文档程序是可以的,但在我在这功能是读串口的单文档里不行为什么啊?
BOOL LoadBitmap( LPCTSTR lpszResourceName );
BOOL LoadBitmap( UINT nIDResource );Return Value
Nonzero if successful; otherwise 0.
2 位图是不是标准的 BMP 格式, 画图打开另存为位图试试看