小弟刚接触VC,现在想做个简单的东西,MFC AppWizard(exe),Dialog based,然后添加个 EditBox  一个Button,现在想要做的就是  按一个按钮 能把EditBox里面的内容保存在硬盘上,跪求存储数据的代码
    回帖必结,全天在线!!!!!!!!!!!!!

解决方案 »

  1.   

    Edit Box里面的数据就是我自己随手输入的   只要能把里面写的东西保存起来就好
      

  2.   

    HANDLE hFile = CreateFile(_T("C:\\MyFile.DAT"),
             GENERIC_WRITE, FILE_SHARE_READ,
             NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);   if (hFile == INVALID_HANDLE_VALUE)
          AfxMessageBox(_T("Couldn't create the file!"));
       else
       {
          // Attach a CFile object to the handle we have.
          CFile myFile(hFile);      char sz[256];
          GetDlgItemText(IDC_EDIT1,sz,255);      // write string, without null-terminator
          myFile.Write(sz, lstrlen(sz));      // We can call Close() explicitly, but the destructor would have
          // also closed the file for us. Note that there's no need to
          // call the CloseHandle() on the handle returned by the API because
          // MFC will close it for us.
          myFile.Close();
       }