I need to print data of many lines. Each line could have text wrapping so the height varies. To do scrolling, I need to derive the total height. Since each line could have different height, I can only go through every line to add up the heights, like below.
void CMyScrollView::OnInitialUpdate()
{
...
for (auto &l: lines)
{
DrawText(dc, l.text, &rc, DT_EDITCONTROL | DT_WORDBREAK | DT_CALCRECT);
total_height += rc.Height();
}
SetScrollSizes(MM_TEXT, CRect(..., total_height));
}
What I've found is that "DrawText(... DT_CALCRECT)" is pretty costly even without actual drawing. Is there way to accelerate the process in such case?