Flying Pigeon Book binaries binary file MFC CArchive implementation Save

Source: Internet
Author: User


Source: Flying Pigeon Book binaries binary file MFC CArchive implementation Save

Flying Pigeon book has been constantly updated in the continuous development, of course, MFC CArchive implementation of saving to binary files is essential. Look at the effect chart first


1 BOOL save2file () 2 {3     bool bopenfiledialog = false;  ----------------------------- -----①4     bool Bvistastyle = false;              &nb sp;   //No vistastyle 5     tchar based_code szfilter[] =   ------------------ --------------②6         _t ("Binary file (*.dat) |*.dat|") 7        & nbsp;_t ("All Files (*.*) |*.*| |"); 8     cstring Path_and_filename; 9 10     cfiledialog Fdlg (Bopenfiledialog, _t ("Dat"), _t ("*.dat"),-------③11     & nbsp;       Ofn_hidereadonly | Ofn_overwriteprompt, Szfilter, NULL, 0,12             bvistastyle);13  & Nbsp;  if (Idok = = Fdlg. DoModal ()) {14         cfile filesave;15         cfilEexception ex;16 17         path_and_filename = Fdlg. GetPathName ();18         if (!filesave.open path_and_filename, cfile::modecreate | 19                  cfile::modewrite | Cfile::typebinary, &ex)) {   ------④20             TCHAR szerror[ 1024];21             Ex. GetErrorMessage (szerror, 1024);22             MessageBox (NULL, Szerror, _t ("hint "), MB_OK);23             return false;24          }25         carchive ar (&filesave, Carchive::store); ---------------------⑤        26         for (int i=0;i <<databuf;= ""------------------------------------------⑥28= ""}29= "" Ar.cloSe (); 30= "" Filesave.close (); 31= "}32=" "33=" "return=" "true;34=" "}[=" "size][attachimg]18[=" "attachimg"


①bopenfiledialog is False, the pop-up dialog box is file Save As, and if true, the pop-up dialog box is file Open;

② file Type filter string, this is only in the saved file type of the optional content, file filtering to be set in the first ③;

③_t ("Dat"), _t ("*.dat") sets the file filter type with the default filename, which displays only filtered files when selected.

The ④cfile::typebinary setting allows the binary to open the file;

⑤ creates a serialized object from an open file, associates ar with FileSave, and sets the Carchive::store

⑥ Direct write to AR is the binary way to write to the file Ar<<databuf, then pay attention to close: [size][= "" Align]

"Ar.close (); [= "" Filesave.close (); [= "" Align]

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.