(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