How would I go about displaying multi-line text in Win32? This code is within my GamePaint() function, and I want to write the top 5 High Scores (stored in an attribute of a struct) out to the screen. I can get it to successfully output a single line using this method…how do I make the TCHAR buffer, szText, store multiple lines? Here’s what I’ve attempted so far:
Original Code:
//draw rect for normal scores
ChangeTextFormat(hDC, hWnd, 1);
TCHAR szText[64];
RECT rcNormalScores = { 268, 122, 436, 330};
RECT rcHardScores = { 37, 122, 198, 330};
//stringstream ssTemp;
for(int i = 0; i < 5; i++)
{
//ssTemp << i;
//display nth Normal score
wsprintf(szText, "%d \n", g_scoreTop[i].num);
DrawText(hDC, szText, -1, &rcNormalScores, DT_LEFT | DT_WORDBREAK);
}
EDIT: Thanks for the info, but I’m still having some difficulty converting between data types. Here’s the error I’m getting:
cannot convert from ‘std::basic_string<_Elem,_Traits,_Ax>’ to ‘std::basic_string<_Elem,_Traits,_Ax>’
EDIT2: Thanks for the help, queen3. I’ve posted the working code below:
Working Code:
ChangeTextFormat(hDC, hWnd, 1);
RECT rcNormalScores = { 37, 122, 198, 330};
RECT rcHardScores = { 268, 122, 436, 330};
stringstream ssTemp;
for(int i = 0; i < 5; i++)
{
ssTemp << g_scoreTop[i].num << " \n";
}
string sTemp = ssTemp.str();
LPCSTR LPTemp = (LPCSTR)sTemp.c_str();
DrawText(hDC, LPTemp, -1, &rcNormalScores, DT_LEFT | DT_WORDBREAK);
DrawText(hDC, LPTemp, -1, &rcHardScores, DT_LEFT | DT_WORDBREAK);
Either of
The first one might work better if you later decide to change DT_LEFT to DT_CENTER.