|
发表于 2020-4-23 20:00:01
|
显示全部楼层
you forget to restore old bmp and old font.
CDC * dc = GetDC() ;
dcMemory.CreateCompatibleDC(dc);
CRect rc;
GetClientRect(&rc);
CBitmap bmp;
bmp.CreateCompatibleBitmap(dc,rc.Width(),rc.Height());
CBitmap* oldBmp = dcMemory.SelectObject(&bmp);
CBrush brush,*oldBrush;
CPen pen,*oldPen;
//draw BK
// brush.Detach();
brush.CreateSolidBrush(m_bkColor);
// pen.Detach();
pen.CreatePen(PS_SOLID,1,m_bkColor);
oldBrush = dcMemory.SelectObject(&brush);
oldPen = dcMemory.SelectObject(&pen);
dcMemory.Rectangle(&rc);
//Draw Text
CFont* oldFont = dcMemory.SelectObject(&m_textFont);
CString strText;
GetWindowText(strText);
dcMemory.SetTextColor(m_textCurrColor);
dcMemory.SetBkMode(TRANSPARENT);
dcMemory.DrawText(strText,&rc,DT_CENTER | DT_VCENTER |DT_WORDBREAK);
dc->BitBlt(0,0,rc.Width(),rc.Height(),&dcMemory,0,0,SRCCOPY);
dcMemory.SelectObject(oldBrush);
dcMemory.SelectObject(oldPen);
dcMemory.SelectObject(oldFont);
dcMemory.SelectObject(oldBmp);
brush.DeleteObject();
pen.DeleteObject();
// bmp.DeleteTempMap();
bmp.DeleteObject();
dcMemory.DeleteDC();
ReleaseDC(dc); |
|