Read the file and write to the edit box

Source: Internet
Author: User

The most recent project needs to read a file in a particular format. and real-time text file content updates to the edit box to go, now the function has been achieved, special will be sent up the source, hoping to help some people, because the level is not high, may be the optimization of code and quality is not very high, forgive me.

Open a Notepad file that already exists
CFileDialog Dlg (True,null,null, ofn_hidereadonly| Ofn_overwriteprompt| Ofn_allowmultiselect,
L "Data Documents (*.jsp) |*.jsp|", AfxGetMainWnd ());

CString Strtem;
if (dlg. DoModal () ==idok)
{
Strtem= dlg. GetPathName ()//Get the filename, you can use this parameter to manipulate the file, such as fopen ()
MessageBox (Strtem)//Use MessageBox to eject the name of the file you selected.
}


CFile file;
CString Filename=strtem;
Char buf[16000]; Read 16K memory
memset (buf,0,16000);//Initialize the memory to prevent garbled characters at the end of the read character
if (!file. Open (Filename,cfile::moderead))
{
MessageBox (L "No files selected!");
Return
}
File. Read (buf,sizeof (BUF));
File. Close ();
AfxMessageBox (BUF);
m_strrecordcon=buf;//to the text box CString m_data

Sets the limit for a byte number, which is 400 bytes

If the file has a number of bytes greater than 400, the pop-up Reminder dialog box
if (M_strrecordcon.getlength () >400)
{
AfxMessageBox (L) The file has a byte number greater than 400, please select a different file. ");

}

UpdateData (FALSE); Data refresh in Notepad to record edit box display
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.