About multi-column listbox
-
I am doing a multi-column listbox,I set its styles:OwnerDraw-Fixed,Multi-column and "No integal height".Then I add virtual function MeasureItem and add code : void CColorListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { // TODO: Add your code to determine the size of specified item CRect rect; GetWindowRect(&rect); ScreenToClient(&rect); lpMeasureItemStruct->itemHeight=rect.Height()/2; lpMeasureItemStruct->itemWidth=rect.Width()/4; } I add a member function to initialize the data and call this function in PreSubclassWindow: void CColorListBox::InitData() { SetItemData(0,RGB(255,0,0)); SetItemData(1,RGB(0,255,0)); SetItemData(2,RGB(0,0,255)); SetItemData(3,RGB(125,0,0)); SetItemData(4,RGB(0,125,0)); SetItemData(5,RGB(0,0,125)); SetItemData(6,RGB(125,125,0)); SetItemData(7,RGB(125,125,125)); } The last I do DrawItem: void CColorListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC); UINT action=lpDrawItemStruct->itemAction; UINT state=lpDrawItemStruct->itemState; CRect rcItem=lpDrawItemStruct->rcItem; //pDC->SetBkMode(TRANSPARENT); if( !(state&ODS_SELECTED) ) pDC->FillSolidRect(&rcItem,(COLORREF)lpDrawItemStruct->itemData); } Is there something wrong in my operation?I set a breakpoint in MeasureItem and debug the program,but it don't run through the breakpoint? I appreciate your comments~
-
I am doing a multi-column listbox,I set its styles:OwnerDraw-Fixed,Multi-column and "No integal height".Then I add virtual function MeasureItem and add code : void CColorListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { // TODO: Add your code to determine the size of specified item CRect rect; GetWindowRect(&rect); ScreenToClient(&rect); lpMeasureItemStruct->itemHeight=rect.Height()/2; lpMeasureItemStruct->itemWidth=rect.Width()/4; } I add a member function to initialize the data and call this function in PreSubclassWindow: void CColorListBox::InitData() { SetItemData(0,RGB(255,0,0)); SetItemData(1,RGB(0,255,0)); SetItemData(2,RGB(0,0,255)); SetItemData(3,RGB(125,0,0)); SetItemData(4,RGB(0,125,0)); SetItemData(5,RGB(0,0,125)); SetItemData(6,RGB(125,125,0)); SetItemData(7,RGB(125,125,125)); } The last I do DrawItem: void CColorListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC); UINT action=lpDrawItemStruct->itemAction; UINT state=lpDrawItemStruct->itemState; CRect rcItem=lpDrawItemStruct->rcItem; //pDC->SetBkMode(TRANSPARENT); if( !(state&ODS_SELECTED) ) pDC->FillSolidRect(&rcItem,(COLORREF)lpDrawItemStruct->itemData); } Is there something wrong in my operation?I set a breakpoint in MeasureItem and debug the program,but it don't run through the breakpoint? I appreciate your comments~
The problem has been solved~ Thanks~
-
The problem has been solved~ Thanks~
You can share your answer;)
WhiteSky