1、选中一行 当CListCtrl失去焦点时 此行依然处于选中状态(不是灰色显示,还是蓝色显示)
2、如何在LISTCTRL中的SUBITEM中显示图标.主要的是实现条件1

解决方案 »

  1.   

    1.Create时包含LVS_SHOWSELALWAYS样式
    2.自画
      

  2.   

    重载NM_CUSTOMDRAW消息
    NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
    //set default draw
    *pResult = CDRF_DODEFAULT;
    if (pLVCD->nmcd.dwDrawStage == CDDS_PREPAINT)
    {
    *pResult = CDRF_NOTIFYITEMDRAW;
    }
    else if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
    {
    // This is the notification message for an item.  We'll request
    // notifications before each subitem's prepaint stage. *pResult = CDRF_NOTIFYSUBITEMDRAW;
    }
    else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
    {//paint the list control items and subitems
    //get the number of item is going to paint
    int nitem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
    //get the number of subitem is going to paint
    int nsubitem = pLVCD->iSubItem;
    //get first selected item position
    POSITION npos = GetFirstSelectedItemPosition();
    if(nitem == GetNextSelectedItem(npos)) //如果被选中使用自绘输出
    { //所画项是选中项
    //get point of default dc objet
    CDC* pdc = CDC::FromHandle(pLVCD->nmcd.hdc);
    CString str;
    CRect rect;
    UINT nFormat = DT_VCENTER | DT_SINGLELINE;
    //get rect of the sub item which is going to paint
    GetSubItemRect(nitem, nsubitem, LVIR_BOUNDS, rect);
    rect.left += 3; //调整自绘输出位置
    //get the context is going to paint on the subitem
    str = GetItemText(nitem,nsubitem);
    pDC->SetTextColor(RGB(0,0,0));//字体颜色,因该是白色
    pDC->FillSolidRect(&rect, RGB(255,255,255));//背景,深蓝色吧,试试
    pDC->SetBkColor(RGB(255,255,255));//字体背景色,颜色同上
    //set back is transparent
    CSize msize;
    //get the context length which is going to paint
    msize = pdc->GetTextExtent(str);
    //paint the text
    pdc->DrawText(str, &rect, nFormat); //自绘输出
    *pResult = CDRF_SKIPDEFAULT; // We've painted everything.
    }
    else
    *pResult = CDRF_DODEFAULT;
    }
    }
      

  3.   

    1.m_ListCtrl.ModifyStyle(0,LVS_SHOWSELALWAYS,0);
    2.http://expert.csdn.net/Expert/topic/2499/2499495.xml?temp=.0897333
      

  4.   

    http://www.embhelp.com/bbs/dispbbs.asp?boardID=14&ID=219