文件名称:ReadFile
- 所属分类:
- 文件操作
- 资源属性:
- [Windows] [Visual C] [源码]
- 上传时间:
- 2012-11-26
- 文件大小:
- 1.8mb
- 下载次数:
- 0次
- 提 供 者:
- 这**
- 相关连接:
- 无
- 下载说明:
- 别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容均来自于网络,请自行研究使用
打开一个TXT文件并显示在EDIT控件中
步骤:
1.新建一个基于对话框的工程,名称为ReadFile
2.在界面上添加一个按钮(IDC_BUTTON1)和一个文本编辑(IDC_EDIT1)
IDC_EDIT1的属性:多行、可下拉滚动条.
3.编辑按钮触发事件(void CReadFileDlg::OnButton1())
void CReadFileDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString sFileFilter="*.hex|*.hex"
CString sFileName
CFileDialog fDlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,sFileFilter,NULL)
fDlg.DoModal()
sFileName=fDlg.GetFileName()
if(sFileName!="")
{
CFile file(sFileName,CFile::modeRead)
int nFileLength=file.GetLength()
char *buffer
HGLOBAL hgl=::GlobalAlloc(GMEM_MOVEABLE,nFileLength+1)
buffer=(char *)::GlobalLock(hgl)
file.Read(buffer,nFileLength)
SetDlgItemText(IDC_EDIT1,buffer)
::GlobalUnlock(hgl)
::GlobalFree(hgl)
}
UpdateData(false)
}
-Open a TXT file and displayed in the EDIT control steps: 1. Create a new dialog-based project, known as the ReadFile2. In the interface to add a button (IDC_BUTTON1) and a text editor (IDC_EDIT1) IDC_EDIT1 properties: multi-line, can be drop-down scroll bar .3. Edit button trigger events (void CReadFileDlg:: OnButton1 ()) void CReadFileDlg:: OnButton1 () (//TODO: Add your control notification handler code here CString sFileFilter =*. hex |*. hex CString sFileName CFileDialog fDlg (true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, sFileFilter, NULL) fDlg.DoModal () sFileName = fDlg.GetFileName () if (sFileName! =) (CFile file (sFileName, CFile:: modeRead) int nFileLength = file.GetLength () char* buffer HGLOBAL hgl =:: GlobalAlloc (GMEM_MOVEABLE, nFileLength+ 1) buffer = (char*):: GlobalLock (hgl) file.Read (buffer, nFileLength) SetDlgItemText (IDC_EDIT1, buffer):: GlobalUnlock (hgl):: GlobalFree (hgl)) UpdateData (false))
步骤:
1.新建一个基于对话框的工程,名称为ReadFile
2.在界面上添加一个按钮(IDC_BUTTON1)和一个文本编辑(IDC_EDIT1)
IDC_EDIT1的属性:多行、可下拉滚动条.
3.编辑按钮触发事件(void CReadFileDlg::OnButton1())
void CReadFileDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString sFileFilter="*.hex|*.hex"
CString sFileName
CFileDialog fDlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,sFileFilter,NULL)
fDlg.DoModal()
sFileName=fDlg.GetFileName()
if(sFileName!="")
{
CFile file(sFileName,CFile::modeRead)
int nFileLength=file.GetLength()
char *buffer
HGLOBAL hgl=::GlobalAlloc(GMEM_MOVEABLE,nFileLength+1)
buffer=(char *)::GlobalLock(hgl)
file.Read(buffer,nFileLength)
SetDlgItemText(IDC_EDIT1,buffer)
::GlobalUnlock(hgl)
::GlobalFree(hgl)
}
UpdateData(false)
}
-Open a TXT file and displayed in the EDIT control steps: 1. Create a new dialog-based project, known as the ReadFile2. In the interface to add a button (IDC_BUTTON1) and a text editor (IDC_EDIT1) IDC_EDIT1 properties: multi-line, can be drop-down scroll bar .3. Edit button trigger events (void CReadFileDlg:: OnButton1 ()) void CReadFileDlg:: OnButton1 () (//TODO: Add your control notification handler code here CString sFileFilter =*. hex |*. hex CString sFileName CFileDialog fDlg (true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, sFileFilter, NULL) fDlg.DoModal () sFileName = fDlg.GetFileName () if (sFileName! =) (CFile file (sFileName, CFile:: modeRead) int nFileLength = file.GetLength () char* buffer HGLOBAL hgl =:: GlobalAlloc (GMEM_MOVEABLE, nFileLength+ 1) buffer = (char*):: GlobalLock (hgl) file.Read (buffer, nFileLength) SetDlgItemText (IDC_EDIT1, buffer):: GlobalUnlock (hgl):: GlobalFree (hgl)) UpdateData (false))
(系统自动生成,下载前可以参看下载内容)
下载文件列表
ReadFile
........\Debug
........\ReadFile.aps
........\ReadFile.clw
........\ReadFile.cpp
........\ReadFile.dsp
........\ReadFile.dsw
........\ReadFile.h
........\ReadFile.ncb
........\ReadFile.opt
........\ReadFile.plg
........\ReadFile.rc
........\ReadFileDlg.cpp
........\ReadFileDlg.h
........\ReadMe.txt
........\res
........\...\ReadFile.rc2
........\resource.h
........\StdAfx.cpp
........\StdAfx.h
........\Debug
........\ReadFile.aps
........\ReadFile.clw
........\ReadFile.cpp
........\ReadFile.dsp
........\ReadFile.dsw
........\ReadFile.h
........\ReadFile.ncb
........\ReadFile.opt
........\ReadFile.plg
........\ReadFile.rc
........\ReadFileDlg.cpp
........\ReadFileDlg.h
........\ReadMe.txt
........\res
........\...\ReadFile.rc2
........\resource.h
........\StdAfx.cpp
........\StdAfx.h