DrawText文本居中显示
代码
1 CRect rectDraw; CDC dc;
2 CRect temp = rectDraw;
3 int height = dc.DrawText(_T("测试文本"), temp, DT_CENTER | DT_WORDBREAK | DT_EDITCONTROL | DT_CALCRECT);//获得文本高度
4 rectDraw.DeflateRect(0, (rectDraw.Height() - height)/2);//改变rect
5 dc.DrawText(_T("测试文本"), rectDraw, DT_CENTER | DT_WORDBREAK | DT_EDITCONTROL);//显示文本
2 CRect temp = rectDraw;
3 int height = dc.DrawText(_T("测试文本"), temp, DT_CENTER | DT_WORDBREAK | DT_EDITCONTROL | DT_CALCRECT);//获得文本高度
4 rectDraw.DeflateRect(0, (rectDraw.Height() - height)/2);//改变rect
5 dc.DrawText(_T("测试文本"), rectDraw, DT_CENTER | DT_WORDBREAK | DT_EDITCONTROL);//显示文本