请问如何在CListCtrl控件中加入图标,在每一行的第一列加上图标用来标识?
最好能给我源码,多谢!email:[email protected]

解决方案 »

  1.   

    See the sample below, FYI:http://www.codeproject.com/listctrl/supergrid.asp
      

  2.   

    http://www.codeproject.com/listctrl/filedroplistctrl.asp
      

  3.   

    若要创建列表控件 (List Control),需要在将新项插入到列表中时提供将要使用的图像列表。下面的示例将说明此过程,其中 m_pImagelist 是 CImageList 类型的指针,m_listctrl 是一个 CListCtrl 数据成员。// create, initialize, and hook up image list
    m_pImageList = new CImageList();
    ASSERT(m_pImageList != NULL);    // serious allocation failure checking
    m_pImageList->Create(32, 32, TRUE,   4, 4);
    m_pImageList->Add(pApp->LoadIcon(IDI_ICONLIST1));
    m_pImageList->Add(pApp->LoadIcon(IDI_ICONLIST2));
    m_listctrl.SetImageList(m_pImageList, LVSIL_NORMAL);
      

  4.   

    楼上的请问m_listctrl.SetImageList(m_pImageList, LVSIL_NORMAL);后如何能在ListCtrl中显示呢,我是做一个文件列表的,如果打开过就用一个开的信封,如果没有则用未找开的信封,类似outlook
      

  5.   

    int j=1;//j为m_pImageList中的第n个图标(或图片)
    //nItem为要设置的Item的序号
    int s=m_ctlList.SetItem(nItem,0,LVIF_IMAGE,"",j,0,LVIF_STATE,0);
      

  6.   

    你把文档基于CListview,再在视类中用
    CListCtrl& m_Listview = (CListCtrl&) GetListCtrl();不是可以了。
    下面是一个对该CListCtrl的显示操作:
    CDaoFieldInfo fieldInfo;
    int nFields;
    CDaoTableDef td(m_pDatabase);
    try
    {
    td.Open(m_strTableName);
    nFields=td.GetFieldCount();
    for(int j=0;j<nFields;j++){
    td.GetFieldInfo(j,fieldInfo);
    int nWidth=m_Listview.GetStringWidth(fieldInfo.m_strName)+30;
    m_Listview.InsertColumn(j,fieldInfo.m_strName,LVCFMT_LEFT,nWidth);
    }
    }
    catch(CDaoException* e)
    {
    e->ReportError();
    e->Delete();
    return;
    }
    td.Close();
    //读取表数据
    int nItem=0;
    m_pImageList = new CImageList();
    m_pImageList->Create(IDB_IMAGELIST, 16, 1, RGB(0,0,0));
    try
    {
    CString strSelect=(_T("Select * From["));
    strSelect+=m_strTableName;
    strSelect+=_T("]");
    m_pRecordset->Open(dbOpenDynaset,strSelect);
    while(!m_pRecordset->IsEOF()){
    COleVariant var;
    var=m_pRecordset->GetFieldValue(0);
    m_Listview.InsertItem(nItem,CCrack::strVARIANT(var));
                               m_Listview.SetImageList(m_pImageList, LVSIL_SMALL); for(int i=1;i<nFields;i++){              var=m_pRecordset->GetFieldValue(i);
    m_Listview.SetItemText(nItem,i,CCrack::strVARIANT(var));
    }
    nItem++;
    m_pRecordset->MoveNext();
    }
    我的PreCreateWindow是这样:
    BOOL CJwglView::PreCreateWindow(CREATESTRUCT& cs)
    {
    cs.style |= LVS_REPORT;
    return CListView::PreCreateWindow(cs);
    }
    如果还是不行我给你源程序。