News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Center button-text

Started by pitter2206, February 07, 2011, 03:36:41 PM

Previous topic - Next topic

pitter2206

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????

TimoVJL

Remove this GetClientRect(hwnd, & rc);
Use same width:
SetRect(&rc, 50, 0, bm.bmWidth, bm.bmHeight);
May the source be with you

pitter2206

arghhhh....

I think I had to see that myself....  :'(

Thank you!