List Control中的内容导入到 .txt文件(可用记事本打开)

 //按下导出按钮后的处理函数
void   CFileDlg::OnButtonExport()  
{
//从保存对话框中输入要保存到的文件和路径
CString   strFileName;
CFileDialog   m_ldFile(FALSE);

                  m_ldFile.m_ofn.lpstrFilter   =   "*.TXT ";
m_ldFile.m_ofn.lpstrDefExt   =   "TXT ";

if   (m_ldFile.DoModal()   ==   IDOK)
{
strFileName   =   m_ldFile.GetPathName();       //包括了路径和文件名
}

//创建文件
char*   pszFileName   =   strFileName.GetBuffer(strFileName.GetLength());
CStdioFile   myFile;
CFileException   fileException;

if   (   !myFile.Open(   pszFileName,   CFile::modeCreate   |      
    CFile::modeWrite   ),   &fileException   )
{
TRACE(   "Can 't   open   file   %s,   error   =   %u\n ",
      pszFileName,   fileException.m_cause   );
        }
       
//文件中写入内容
                  int   iColSum   =   3;       //List中的栏数
int   iCount   =   m_List.GetItemCount();
       
for   (int   iItem   =   0;   iItem   <   iCount;   iItem++)
for   (int   iCol   =   0;   iCol   <   iColSum;   iCol++)
{
CString   strTemp   =   m_List.GetItemText(   iItem,   iCol);

if   (iCol   ==   0)
                                lstrcat(strTemp.GetBuffer(strTemp.GetLength()),   "\t ");
else
lstrcat(strTemp.GetBuffer(strTemp.GetLength()),   "\n ");

myFile.WriteString(strTemp.GetBuffer(strTemp.GetLength()));
"open ",  
  pszFileName,  
  NULL,  
}


//是否立即查看该文件
if   (MessageBox( "已保存,要查看吗 ",   "完成 ",   MB_YESNO)   ==   IDYES)
{
ShellExecute(NULL,   

  NULL,  
  SW_SHOWNORMAL);
}

//关闭文件
myFile.Close();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值