Click to See Complete Forum and Search --> : Center text in a listbox?


Magnus Ohlin
April 7th, 1999, 03:12 AM
Hiya!

I'm wondering if its possible to center the text in a CListBox. Both vertical and horisontel.

Thanks
Magnus

jacques
April 7th, 1999, 06:17 AM
One of the best way is to use an ownder-deawn list box
1 ) modify your resource to have an Owner draw and Has string styles
2 ) intercepeit the owner draw message
3 ) Draw your text
....
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rcLine(lpDrawItemStruct->rcItem);
GetText(lpDrawItemStruct->itemID, strChaine);

there you have a CDC, a CString and a Rect.
DrawText(... DT_CENTER | DT_VCENTER)

there are many samples in code guru

One tip you are supposed to fraw the line diffrently depending of the focus and state
if ((lpDrawItemStruct->itemState & ODS_SELECTED)
or (lpDrawItemStruct->itemAction & ODA_SELECT))
{
CRect Unrect(lpDrawItemStruct->rcItem);
pDC->InvertRect(&Unrect);
...