Hi there,
I try to center text which has sometimes 2 lines.
So I use DrawText with DT_WORDBREAK and DT_CALCRECT. That would be fine, if the button text would be centered.
I tried this to fix it:
GetClientRect(hwnd, & rc);
SetRect(&rc, 0, 0, bm.bmWidth, bm.bmHeight);
rcT.bottom = DrawText(lpDrawItem->hDC, buttons[nIdx].text, lstrlen(buttons[nIdx].text), &rc, DT_WORDBREAK | DT_CALCRECT);
int textHeight = bm.bmHeight/2 - rcT.bottom/2 ; //calc the half of the difference between bm.bmWidth and the result of rct.bottom to use it as int yTop in rcT
SetRect(&rcT, 50, textHeight, bm.bmWidth, bm.bmHeight);
DrawText(lpDrawItem->hDC, buttons[nIdx].text, lstrlen(buttons[nIdx].text), &rcT, DT_WORDBREAK | DT_LEFT);
The result is, that some buttons are centered and some not. ???
Where is my missunderstanding??? Could you please give me a hint????
Remove this GetClientRect(hwnd, & rc);
Use same width:
SetRect(&rc, 50, 0, bm.bmWidth, bm.bmHeight);
arghhhh....
I think I had to see that myself.... :'(
Thank you!