15,979
社区成员
发帖
与我相关
我的任务
分享
void CWaitWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
UpdateText(&dc, m_strText, m_TextRect);
// Do not call CWnd::OnPaint() for painting messages
}
void CWaitWnd::UpdateText(CDC *pDC, LPCTSTR lpszText, CRect &TextRect)
{
if (!IsWindow(m_hWnd))
return;
if (TextRect.IsRectEmpty())
return;
ASSERT(lpszText);
if (!lpszText)
return;
BOOL bReleaseDC = FALSE;
if (!pDC)
{
pDC = GetDC();
bReleaseDC = TRUE;
}
// double buffer the drawing
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, TextRect.Width(), TextRect.Height());
CBitmap *pOldBitmap = dcMem.SelectObject(&bmp);
dcMem.SetBkColor(GetSysColor(COLOR_BTNFACE));
dcMem.SetBkMode(OPAQUE);
CRect rect(0, 0, TextRect.Width(), TextRect.Height());
dcMem.FillSolidRect(&rect, GetSysColor(COLOR_BTNFACE));
CFont *pOldFont = dcMem.SelectObject(&m_font);
dcMem.DrawText(lpszText, -1, &rect, DT_LEFT);
// end double buffering
pDC->BitBlt(TextRect.left, TextRect.top,
TextRect.Width(), TextRect.Height(), &dcMem,
0, 0, SRCCOPY);
dcMem.SelectObject(pOldFont);
dcMem.SelectObject(pOldBitmap);
bmp.DeleteObject();
dcMem.DeleteDC();
if (bReleaseDC)
ReleaseDC(pDC);
}