如上,最好有例子。  谢谢!

解决方案 »

  1.   

    做一个循环阿,读取一个Item的内容到CString中,然后写入文件中,看是否还能取到Item,如果可以就重复上述操作,不能就结束。
      

  2.   

    好像只能自己一个个取出来写到文件里。BOOL CNSListCtrl::SaveItemToFile(FILE* fp)
    {
    if(fp == NULL)
    {
    return FALSE;
    } TCHAR szText[256];
    LV_COLUMN lvc;
    lvc.mask = LVCF_TEXT | LVCF_FMT | LVCF_WIDTH;
    lvc.pszText = szText;
    lvc.cchTextMax = sizeof(szText);

    CString strText;
    CDWordArray ayFormat;
    WORD wJustify;
    for(int nColumn = 0; GetColumn(nColumn, &lvc); nColumn++)
    {
    wJustify = ST_LEFT;
    switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
    {
    case LVCFMT_RIGHT:
    wJustify = ST_RIGHT;
    break;
    case LVCFMT_CENTER:
    wJustify = ST_CENTER;
    break;
    }
    ayFormat.Add(MAKELONG(wJustify, (WORD)lvc.cx));
    strText += FormatColumnString(szText, ayFormat[nColumn]);
    strText += _T("\t");
    }
    if(strText.IsEmpty())
    {
    return FALSE;
    }
    strText += _T("\r\n");
    _ftprintf(fp, strText);
    for(int i = 0; i < GetItemCount(); i++)
    {
    strText.Empty();
    for(int j = 0; j < nColumn; j++)
    {
    strText += FormatColumnString(GetItemText(i, j), ayFormat[j]);
    strText += _T("\t");
    }
    strText += _T("\r\n");
    _ftprintf(fp, strText);
    }
    return TRUE;
    }
      

  3.   

    文件那一部分具体如何操作呢?比如,如何将“abcdefg"写入到一个。txt,都需那些函数?
      

  4.   

    wwwsq(wwwsq) 已经告诉你答案了。关于写文件,还可以直接使用API函数:如OpenFile和WriteFile等。
      

  5.   

    向文件中写就用CFile类中的WriteFile()函数。
      

  6.   

    很多的函数
    _open()
    _write()
    _close()
    就可以
    其他如CFILE,CSTDFILE,FILE类都可以完成
      

  7.   

    谢谢各位!
    本人最后采用的方法如下,功能可以实现,不知有无不妥之处!//按下导出按钮后的处理函数
    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())); }
    //是否立即查看该文件
    if (MessageBox("已保存,要查看吗", "完成", MB_YESNO) == IDYES)
    {
    ShellExecute(NULL, 
    "open", 
     pszFileName, 
     NULL, 
     NULL, 
     SW_SHOWNORMAL);
    } //关闭文件
    myFile.Close();
    }
      

  8.   

    保存的时候最好保存左右对齐格式和数据长度。这样保存好的text文件才方便查看。