MFC read-Write files

Source: Internet
Author: User
Tags lua

(1) Read the file

VOID cscale3dccontrol::readlaufile (CString Strfilename,cricheditctrl & richEdit) {CString strFilePath = Getapplicationpath () + strFileName;   CFile file (strFilePath, cfile::moderead); char * Pbuf;dword Dwfilelen; Defines the variable Dwfilelen = file that stores the length of the files.  GetLength ();p buf = new Char[dwfilelen + 1];p Buf[dwfilelen] = 0; End of the last 10 indicates that the file is closed. Read (PBuf, Dwfilelen); Uses_conversion;richedit.setwindowtext (a2w (PBUF)); Getkeywordfromtext (a2w (PBUF)); file. Close ();}

(2) Writing files

VOID cscale3dccontrol::saveluafile (CRichEditCtrl & RichEdit, CString strFileName) {CString strpath = Getapplicationpath () + _t ("lua\\") + strFileName; CFile File (strpath,cfile::modecreate | Cfile::modewrite); CString Strtemp;richedit.getwindowtext (strtemp); Uses_conversion;file. Write (W2A (strtemp), strlen (W2A (strtemp))); file. Close ();}

(3) All filenames under Search Folder

Void cscale3dccontrol::getfilefromdirectory (cstring csdirpath, clistbox & list)// Csdirpath the folder name, put the JPG text under the folder                                  The name of the        //piece is stored in the container  m_filelist, if no type     // Then the csdirpath+= "\\*.jpg" was changed to csdirpat+= "\*."     {m_filelist.clear (); list. Resetcontent (); Csdirpath = getapplicationpath () +csdirpath+ _t ("\\*.lua"); handle file; Win32_find_data filedata;file = findfirstfile (Csdirpath.getbuffer (),  &fileData);   (File != invalid_handle_value) {m_filelist.push_back (filedata.cfilename); list. AddString (Filedata.cfilename); Bool bstate = false;bstate = findnextfile (file,  &filedata);while  (bstate)  {m_filelist.push_back (filedata.cFileName); list. AddString (Filedata.cfilename); Bstate = findnextfile (File, &filedata);}} Else{;// afxmessagebox ("There are no SHP files in the folder! ");}} Cstring cscale3dccontrol::getapplicationpath () {wchar  buff[255] = { 0 };:: GetModuleFileName (0, buff, 255); Cstring strappfullname;strappfullname.format (_t ("%s"),  buff); cstring strapppath = _t (""); Strapppath = strappfullname.left ( Strappfullname.reversefind (' \ \ ')  + 1); Return strapppath;}


MFC read-Write files

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.