CSize CInfoBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz) { // Get border size (values will be negative) CRect rBorder; rBorder.SetRectEmpty(); CalcInsideRect(rBorder, bHorz); // Based on the available width minus the border area, // calculate the necessary Y value to hold the text CRect rCalc(0, 0, m_cxAvailable - (-rBorder.Width()), 0); { CClientDC dc(this); CFont* pOldFont = dc.SelectObject(&m_font); dc.DrawText(m_caption, -1, rCalc, DT_CALCRECT | DT_EDITCONTROL | DT_EXTERNALLEADING | DT_LEFT | DT_WORDBREAK); if (pOldFont != NULL) dc.SelectObject(pOldFont); } // The Y value is the sum of the calculated height from DrawText, // plus the top and bottom border. CSize size; size.cx = 32767; size.cy = rCalc.Height(); size.cy += (-rBorder.Height()); return size; }
int CInfoBar::GetHeight(int cx) { // Get border size (values will be negative) CRect rBorder; rBorder.SetRectEmpty(); CalcInsideRect(rBorder, TRUE); // Based on the available width minus the border area, // calculate the necessary Y value to hold the text CRect rCalc(0, 0, cx - (-rBorder.Width()), 0); CClientDC dc(this); CFont* pOldFont = dc.SelectObject(&m_font); UINT nFormat = DT_CALCRECT|DT_EDITCONTROL|DT_EXTERNALLEADING|DT_LEFT|DT_WORDBREAK; dc.DrawText(m_sCaption, -1, rCalc, nFormat); if (pOldFont != NULL) dc.SelectObject(pOldFont); // The Y value is the sum of the calculated height from DrawText, // plus the top and bottom border. int cy = rCalc.Height(); cy += (-rBorder.Height()); return cy; }