CListCtrl *pLC1;
CImageList* m_pImgList;   // CFormView2 消息处理程序UINT loadbmpthd(LPVOID argv1) ////在mainfrm.cpp中启动该函数线程。
{
if(pLC1==NULL)
return 0;
CBitmap* pImage = NULL;  
pImage = new CBitmap();
int i=0;
int bmap=IDB_BITMAP3;
HBITMAP bitm;char str[200];CFileFind finder;
CString sName;
CString sName1;BOOL bk = finder.FindFile("c:\\adpicture\\*.bmp");
while(bk)
{
bk = finder.FindNextFile();
sName = finder.GetFileName();
//AfxMessageBox(sName);
sName1="c:\\adpicture\\"+sName;
bitm=(HBITMAP)LoadImage( NULL,sName1 , IMAGE_BITMAP, 176, 120,
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
pImage->Attach(bitm);//pImage->LoadBitmapA();
int imgP=m_pImgList->Add(pImage,RGB(125,125,0));pLC1->InsertItem(imgP,sName);//为什么跑到这里程序崩溃?InsertItem为什么执行不了?
pImage->DeleteObject();
}return 0;
}
void CFormView2::OnInitialUpdate(void)
{pLC1 = (CListCtrl *)GetDlgItem(IDC_LIST2);
m_pImgList=new CImageList;
m_pImgList->Create (176,120,ILC_COLOR32,20,20);//前两个参数是设置图象大小的
m_pImgList->SetBkColor(RGB(125,125,0));
pLC1->SetImageList(m_pImgList,0);//LVS_SMALLICON LVSIL_NORMAL
}

解决方案 »

  1.   

    你用的是:
    HTREEITEM InsertItem( LPCTSTR lpszItem, int nImage, int nSelectedImage, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);所以应该是:
    pLC1->InsertItem(sName,imgP,imgP);//
    再看看pLC1对不对
      

  2.   

    pLC1->InsertColumn(0,strLabel);//列标签
    {
      pLC1->InsertItem(imgP,"");
    pLC1->SetItemText(row,col,sName);
    }
      

  3.   

    我用的是pLC1->InsertItem(imgP,sName,imgP);//color[imgP],
    编译通过,但运行到InsertItem崩溃。
      

  4.   

    有知道的朋友麻烦告诉我!貌似InsertItem放在类外就是不行啊、
      

  5.   

    所以应该是:
    pLC1->InsertItem(sName,imgP,imgP);//sName=文本,imgP普通图标,imgP被选择后图标。
    再看看pLC……
      

  6.   

    因为整个程序全写在OnInitialUpdate里面,而指针还是定义在类外,程序跑起来正常啊。
      

  7.   

    pLC1->InsertItem
    pLC1->SetRedraw(TRUE);
    pLC1->Invalidate();
    等等函数放在类外都不能执行,放在void CFormView2::OnInitialUpdate(void)
    里面又一律可以了,请问什么原因啊?难到是因为CListCtrl控件静态创建在CFormView2上的原因吗?崩溃,急盼朋友们解答!谢谢!!!
      

  8.   

    搞错了,是CListCtrl:
    int InsertItem( int nItem, LPCTSTR lpszItem, int nImage );// index,sName="Text", imgP
    index是表中项的索引,不是图标索引
      

  9.   

    是不是int imgP=m_pImgList->Add(pImage,RGB(125,125,0));就有问题?
      

  10.   

    void CFormView2::OnInitialUpdate(void)
    {
    m_pImgList=new CImageList;
    m_pImgList->Create (176,120,ILC_COLOR32,20,20);//前两个参数是设置图象大小的
             pLC1=new CListCtrl;
            pLC1->Create(LVS_ICON,CRect(10, 18, 32, 21),this,IDC_LIST2);
    m_pImgList->SetBkColor(RGB(125,125,0));
    pLC1->SetImageList(m_pImgList,0);//LVS_SMALLICON LVSIL_NORMA
    CBitmap*    pImage = NULL; 
    pImage = new CBitmap();
    int i=0;
    int bmap=IDB_BITMAP3;
    HBITMAP bitm; CFileFind finder;
    CString sName;
    CString sName1; BOOL bk = finder.FindFile("c:\\picture\\*.bmp");
    while(bk)
    { bk = finder.FindNextFile();
    sName = finder.GetFileName();
    sName1="c:\\picture\\"+sName; bitm=(HBITMAP)LoadImage( NULL,sName1 , IMAGE_BITMAP, 176, 120,
    LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
    pImage->Attach(bitm); int imgP=m_pImgList->Add(pImage,RGB(125,125,0)); pLC1->InsertItem(imgP,sName,imgP);//color[imgP], pImage->DeleteObject();
    }
    }
    这段代码动态创建CListCtrl控件,可怎么没有图片显示?
      

  11.   

    pLC1->InsertItem(i,sName,imgP);//color[imgP],
    i++;
      

  12.   

    试了不行哦,imgP其实就是i的作用啊,imgP是变化的。问题是CListCtrl *pLC1这个控件在mfc里都不显示出来(如果出来应该有个框),可我调试CListCtrl pLC1创建成功了啊。难道要设置可见?怎么设置?朋友们帮帮忙啊!
      

  13.   

    http://blog.vckbase.com/arong/archive/2005/12/03.html
      

  14.   

    恩,我一会好好看。
    可是我不启动线程还是没图片啊(不崩溃),用了这个pLC1->ShowWindow(SW_SHOW);也不行哦。
      

  15.   

    InsertItem可以直接插入图片?其第一个参数是List自己元素的下标,不是你那个图片列表的下标,你需要处理第二个参数中和图片相关的标志来操作图片,看看MSDN吧