44 MFC打开文件并在Edit中显示 - 雪炭网

MFC打开文件并在Edit中显示2015-02-13 13:32:51

( 3人已投票,[高质量] )
分享:
31.3K

Add "Open afile and display the content in a EDIT Control":

MFC打开文件并在Edit中显示

CFileDialog *lpszOpenFile;  
CStdioFile file;
CString filePathName;
int row;
CString result;
//Create a dialog
lpszOpenFile = new CFileDialog
    (TRUE,"","",OFN_FILEMUSTEXIST |OFN_HIDEREADONLY , "文件类型(*.txt)|*.txt|所有文件(*.*)|*.*|"); 
  if(lpszOpenFile->DoModal() == IDOK )//If Clicked the OK button
  {
    filePathName = lpszOpenFile->GetPathName();//Get the file dir
    SetWindowText(filePathName);//display the dir in the dialog
  }
  if(filePathName == "") return;
  if(!file.Open(filePathName,CFile::modeRead))
  {
    MessageBox("Can not open file!");
    return;
  }
  CString strLine,strTemp;
  row = 0;
  while(file.ReadString(strLine))
  {
    char *str = strLine.GetBufferSetLength(strLine.GetLength());
    char *p;
    if(strLine!="")
    {
      for (p=strtok(str,";");p!=NULL;p=strtok(NULL,";"))
      {
        strTemp = p;
        result+=strTemp;
      }
      row ++;
    }
  } 
  delete lpszOpenFile;//relese the handle
  m_strText = _T(result); 
//In Dlg DoDataExchange Add this Code:DDX_Text(pDX, IDC_EDIT1, m_strText);  
UpdateData(false);






头像

snowcoal
  • MFC
  • 打开文件
  • Edit

本文标签:

MFC打开文件Edit

收藏到我的私密空间

标题:MFC打开文件并在Edit中显示

作者:柳岸花明

你暂未登录,请登录后才可收藏至您的私密空间 确认取消
雪炭网

键盘操作 更便捷 -雪炭网雪中送炭-乐趣无限

如果本站的内容有幸帮助到了您,建议您了解一下当页的广告内容哦,我们的进步离不开您的支持,Thank you~