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
}
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
}
HTREEITEM InsertItem( LPCTSTR lpszItem, int nImage, int nSelectedImage, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);所以应该是:
pLC1->InsertItem(sName,imgP,imgP);//
再看看pLC1对不对
{
pLC1->InsertItem(imgP,"");
pLC1->SetItemText(row,col,sName);
}
编译通过,但运行到InsertItem崩溃。
pLC1->InsertItem(sName,imgP,imgP);//sName=文本,imgP普通图标,imgP被选择后图标。
再看看pLC……
pLC1->SetRedraw(TRUE);
pLC1->Invalidate();
等等函数放在类外都不能执行,放在void CFormView2::OnInitialUpdate(void)
里面又一律可以了,请问什么原因啊?难到是因为CListCtrl控件静态创建在CFormView2上的原因吗?崩溃,急盼朋友们解答!谢谢!!!
int InsertItem( int nItem, LPCTSTR lpszItem, int nImage );// index,sName="Text", imgP
index是表中项的索引,不是图标索引
{
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控件,可怎么没有图片显示?
i++;
可是我不启动线程还是没图片啊(不崩溃),用了这个pLC1->ShowWindow(SW_SHOW);也不行哦。