2010년 11월 13일 토요일

SaveListBoxData(CListBox& lbLog)

void CDeleteThisDlg::SaveListBoxData(CListBox& lbLog)
{
 CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
     "log 파일 (*.log)|*.log||", this);
 if(dlg.DoModal() == IDCANCEL)
   return;
 int nCount = lbLog.GetCount();
 if(nCount <=0)
  return;
 //파일 생성...
 CString strFileName = dlg.GetPathName();
 if(dlg.GetFileExt() == "")
  strFileName += ".log";
 CStdioFile file;
 CFileException ex;
 TRY {
  file.Open( strFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeText);
 }
 CATCH(CFileException, ex) {
  TCHAR szError[1024];
  ex->GetErrorMessage(szError, 1024);
  AfxMessageBox(szError);
  return;
 }
 END_CATCH
 CString strTemp;
 for(int i=0; i<nCount; ++i) {
  lbLog.GetText(i, strTemp); 
  strTemp += "\n";
  file.WriteString(strTemp);
 }
 file.Close();
}

댓글 없음:

댓글 쓰기