void CBigIcon::CenterText(CClientDC &dc, LPCSTR lpszStatus, int top) { int nMargin; CRect rect; TEXTMETRIC tm; // Leave a horizontal margin equal to the widest character VERIFY(dc.GetTextMetrics(&tm)); nMargin = tm.tmMaxCharWidth; // Compute the opaque rect rect.left = nMargin; rect.right = m_sizeBitmap.cx - nMargin; rect.top = top; rect.bottom = rect.top + tm.tmHeight; // We need to compute where to draw the text so it is centered // horizontally int x = rect.left; CSize extent = CIntlWin::GetTextExtent(0, dc.m_hDC, lpszStatus, XP_STRLEN(lpszStatus)); if (extent.cx < rect.Width()) x += (rect.Width() - extent.cx) / 2; // Draw opaquely so we can avoid erasing the old text dc.ExtTextOut(x, rect.top, ETO_OPAQUE, &rect, lpszStatus, strlen(lpszStatus), NULL); }
void CDlgCalcDlg::UpdateDisplay(LPCTSTR pszDisplay) { CClientDC dc (this); CFont* pOldFont = dc.SelectObject (GetFont ()); CSize size = dc.GetTextExtent (pszDisplay); CRect rect = m_rect; rect.InflateRect (-2, -2); int x = rect.right - size.cx - m_cxChar; int y = rect.top + ((rect.Height () - m_cyChar) / 2); dc.ExtTextOut (x, y, ETO_OPAQUE, rect, pszDisplay, NULL); dc.SelectObject (pOldFont); }