MFC  에서 ListBox에 출력 된 정보들을 *.txt 파일로 저장할 때

 

void CContentLogDlg::OnSave(void)
{

 LPCTSTR lpszFilter = _T( "txt파일(*.txt)") ;

 // 파일 공용컨트롤 대화상자 인스턴스 생성.. 첫번째 인자가 TRUE 이면 읽기 FALSE 이면 쓰기.
 CFileDialog FileDlg( FALSE, _T( ".txt" ), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, lpszFilter, NULL );

 if( FileDlg.DoModal() == IDOK )   
{

   CString sPath( FileDlg.GetPathName() );
   CFile File( sPath, CFile::modeWrite | CFile::modeCreate );

   CString sData = NULL;
   
    for( int i=0; i < m_ctrLogList.GetCount() ; ++i){
        m_ctrLogList.GetText( i, sData );
        sData += _T("\r\n");
        File.Write( (LPCTSTR)sData, sData.GetLength() * sizeof(TCHAR) );
  }

File.Flush();
File.Close();

CContentLogDlg::AddLog("File Save Complite!!");


 }

+ Recent posts