MFC打开文件并在Edit中显示2015-02-13 13:32:51
( 3人已投票,[高质量] )
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);
上一篇:爆炸特效素材下载-UI制作
下一篇:MFC圆角框实现代码-两种方式