1》产生:
2》指定size:
- case WM_MEASUREITEM://ODT_LISTBOX
- if((UINT) wParam==IDC_LISTBOX)
- {
- LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
- lpmis->itemWidth=400;
- lpmis->itemHeight=22;
- }
- break;
3》画:
- case WM_DRAWITEM:
- if((UINT) wParam==IDC_LISTBOX)
- {
- LPDRAWITEMSTRUCT pDI=(LPDRAWITEMSTRUCT) lParam;
- HBRUSH brsh=CreateSolidBrush(RGB(255-30*pDI->itemID, 128+40*pDI->itemID, 128+40*pDI->itemID));//yellow
- FillRect(pDI->hDC,&pDI->rcItem,brsh);
- DeleteObject(brsh);
- // text
- SetBkMode(pDI->hDC,TRANSPARENT);
- char szText[260];
- SendMessage(m_hListBox,LB_GETTEXT,pDI->itemID,(LPARAM)szText);
- const DWORD dwStyle = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS;
- DrawText(pDI->hDC, szText, strlen(szText), &pDI->rcItem, dwStyle);
- }
- break;
4》要点:| LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,