When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.你必须首先选择一个bitmap到内存dc用CreateCompitableBitmap CBitmap bmp; bmp.CreateCompatibleBitmap(pDC, ClientRect.Width(), ClientRect.Height()); HGDIOBJ hOldBmp = memDC.SelectObject(bmp); memDC.FillSolidRect(ClientRect, RGB(255, 255, 255));
CreateCompatiblDC创建一个内存dc
然后在内存dc中textout
最后再用bitblt拷贝到显示的dc中
CRect ClientRect;
GetClientRect(&ClientRect);
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CFont * oldFont=memDC.SelectObject(&m_OutFont);
m_screenPos=0;
for(stringlist::iterator pos=pDoc->m_ChatInfoLog.begin();pos != pDoc->m_ChatInfoLog.end();++pos)
{
memDC.TextOut(10,m_screenPos*12,(*pos).c_str());
++m_screenPos;
}
memDC.SelectObject(oldFont);
pDC->BitBlt(0,0,ClientRect.Width(),ClientRect.Height(),&memDC,0,0,SRCCOPY);
为什么不行,没有显示出来!
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, ClientRect.Width(), ClientRect.Height());
HGDIOBJ hOldBmp = memDC.SelectObject(bmp); memDC.FillSolidRect(ClientRect, RGB(255, 255, 255));