//初始化对话框中,选择多个文件
m_ImageList.Create(16,16,ILC_COLOR24,0,1); //创建图示
m_list.SetImageList(&m_ImageList,LVSIL_SMALL); //与列表控件相关连
m_list.SetExtendedStyle(m_list.GetExtendedStyle()| LVS_EX_GRIDLINES|LVS_EX_SUBITEMIMAGES|LVS_EX_FULLROWSELECT);
//标题
m_list.InsertColumn(0,_T("名称"),LVCFMT_LEFT,200);
m_list.InsertColumn(1,_T("路径"),LVCFMT_LEFT,350);
//初始化对话框中,选择多个文件
m_ImageList.Create(16,16,ILC_COLOR24,0,1); //创建图示
m_list.SetImageList(&m_ImageList,LVSIL_SMALL); //与列表控件相关连
m_list.SetExtendedStyle(m_list.GetExtendedStyle()| LVS_EX_GRIDLINES|LVS_EX_SUBITEMIMAGES|LVS_EX_FULLROWSELECT);
//标题
m_list.InsertColumn(0,_T("名称"),LVCFMT_LEFT,200);
m_list.InsertColumn(1,_T("路径"),LVCFMT_LEFT,350);
view plaincopy to clipboardprint?
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT ,"所有文件(*.*)|*.*|/
Shell文件(*.sh)|*.sh|Csv文件(*.csv)|*.csv||",this);
DWORD MAXFILE = 4000;
dlg.m_ofn.nMaxFile = MAXFILE;
char* pc = new char[MAXFILE];
dlg.m_ofn.lpstrFile = pc;
dlg.m_ofn.lpstrFile[0] = NULL;
if (IDOK==dlg.DoModal())
{
int nCount = 0;
POSITION pos = dlg.GetStartPosition();
while (pos != NULL)
{
CString filePathName = dlg.GetNextPathName(pos);
int j = filePathName.ReverseFind('//');
CString fileName = filePathName.Right(filePathName.GetLength()-j-1);
SHFILEINFO info;
HIMAGELIST hImageList=NULL;
memset((char*)&info,0,sizeof(info));
hImageList = (HIMAGELIST)SHGetFileInfo(filePathName,FILE_ATTRIBUTE_NORMAL,&info,sizeof(&info), SHGFI_ICON|SHGFI_SMALLICON|SHGFI_OPENICON|SHGFI_DISPLAYNAME);//关键所在
m_ImageList.Add(info.hIcon);
int indexIcon = m_ImageList.Add(info.hIcon);
//判断文件是否存在,如果存在就覆盖
for (int i=0; i!=m_list.GetItemCount(); i++)
{
CString strLine = m_list.GetItemText( i, 0 );
if (strLine.Compare(fileName)==0)//文件已经存在
{
m_list.DeleteItem(i);
break;
}
}
m_list.InsertItem(nCount,NULL,indexIcon);//声明一行
m_list.SetItemText(nCount,0,fileName);//名称
m_list.SetItemText(nCount,1,filePathName);//路径
nCount++;
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yyyzlf/archive/2009/10/26/4730440.aspx