Visual Studio 6Visual C++ 7.0Windows 2000Visual C++ 6.0Windows XPMFCIntermediateDevVisual StudioWindowsC++
Editable Multi-line ListBox






4.25/5 (18 votes)
Mar 26, 2003

132331

2537
A ListBox control providing multi-line support.
Introduction
If you take a look at the snapshot and run the .exe file you`ll realise that there`s nothing I need to say here. I needed this control with item editing, insertion, deletion, and moving capabilities and I asked, "why not share it with people?"
Using the Code
It`s very easy to use just add a variable based on the class and that`s all. You work with it like a normal listbox.
// // powered by NetControl.ro // // ............. void CListBoxXP::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CString szBuf=""; COLORREF col; if(((int)lpDrawItemStruct->itemID==edited)&&(IsWindow(hHelper))) return; { GetText(lpDrawItemStruct->itemID,szBuf); SetTextColor(lpDrawItemStruct->hDC,RGB(0,0,0)); RECT r; memcpy((void*)&r,&lpDrawItemStruct->rcItem,sizeof(RECT)); if(itm==(int)lpDrawItemStruct->itemID) { HBRUSH br; br=::CreateSolidBrush(LightenColor(
GetSysColor(COLOR_HIGHLIGHT),0.9)); ::FillRect(lpDrawItemStruct->hDC,
&lpDrawItemStruct->rcItem,br); ::DeleteObject(br); } else { FillRect(lpDrawItemStruct->hDC,
&lpDrawItemStruct->rcItem,
(HBRUSH)GetStockObject(WHITE_BRUSH)); }
r.left+=5; r.top+=2; col=RGB(255,255,255); if(lpDrawItemStruct->itemState & ODS_SELECTED) { col=RGB(220,220,220); HBRUSH br; br=::CreateSolidBrush(LightenColor(
GetSysColor(COLOR_HIGHLIGHT),0.75)); ::FillRect(lpDrawItemStruct->hDC,
&lpDrawItemStruct->rcItem,br); ::DeleteObject(br); } if(lpDrawItemStruct->itemState & ODS_FOCUS) { HBRUSH br; br = ::CreateSolidBrush(LightenColor(
GetSysColor(COLOR_HIGHLIGHT),0.5)); ::FrameRect(lpDrawItemStruct->hDC,
&lpDrawItemStruct->rcItem,br); ::DeleteObject(br); } SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT);
r.left-=3; r.top-=2; if(CountLines(szBuf) > 1) DrawText(lpDrawItemStruct->hDC,szBuf,
strlen(szBuf),&r,
DT_LEFT|DT_TOP|DT_WORDBREAK); else DrawText(lpDrawItemStruct->hDC,szBuf,
strlen(szBuf),&r,
DT_LEFT|DT_VCENTER|DT_SINGLELINE); } } void CListBoxXP::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { HDC hDC; TEXTMETRIC tm; char szBuf[512]=""; ::SendMessage(this->m_hWnd, LB_GETTEXT,
(WPARAM)lpMeasureItemStruct->itemID,(LPARAM)szBuf);
hDC = ::GetDC(this->m_hWnd); CRect r; GetClientRect(r); ::GetTextMetrics(hDC, &tm); lpMeasureItemStruct->itemHeight=(tm.tmHeight)*CountLines(szBuf); ::ReleaseDC(this->m_hWnd, hDC); } // ...