就像我现在要开发一个像 windows 里的 记事本 一样的软件,
非得要用到序列化吗》?
还有其他的途径吗?
望高手解决小弟的困惑,谢谢
[此贴子已经被作者于2006-5-22 21:48:02编辑过]
文档类可以基于CEditView
文件读取可以用CFile类,定义如下:
class CFile : public CObject
{
DECLARE_DYNAMIC(CFile)
public:
// Flag values
enum OpenFlags {
modeRead = 0x0000, //只读
modeWrite = 0x0001, //只写
modeReadWrite = 0x0002, //读写兼用
shareCompat = 0x0000,
shareExclusive = 0x0010,
shareDenyWrite = 0x0020, //非独占模式只写
shareDenyRead = 0x0030, //非独占模式只读
shareDenyNone = 0x0040,//非独占模式读写兼用
modeNoInherit = 0x0080,
modeCreate = 0x1000, //创建文件(不管有没有文件)
modeNoTruncate = 0x2000, //与modeCreate一起用,只有在没有文件时才创建文件
typeText = 0x4000, // typeText and typeBinary are used in
typeBinary = (int)0x8000 // derived classes only
};
enum Attribute {
normal = 0x00,
readOnly = 0x01,
hidden = 0x02,
system = 0x04,
volume = 0x08,
directory = 0x10,
archive = 0x20
};
enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };
enum { hFileNull = -1 };
// Constructors
CFile();
CFile(int hFile);
CFile(LPCTSTR lpszFileName, UINT nOpenFlags);
// Attributes
UINT m_hFile;
operator HFILE() const;
virtual DWORD GetPosition() const;
BOOL GetStatus(CFileStatus& rStatus) const;
virtual CString GetFileName() const;
virtual CString GetFileTitle() const;
virtual CString GetFilePath() const;
virtual void SetFilePath(LPCTSTR lpszNewName);
// Operations
virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags,
CFileException* pError = NULL);
static void PASCAL Rename(LPCTSTR lpszOldName,
LPCTSTR lpszNewName);
static void PASCAL Remove(LPCTSTR lpszFileName);
static BOOL PASCAL GetStatus(LPCTSTR lpszFileName,
CFileStatus& rStatus);
static void PASCAL SetStatus(LPCTSTR lpszFileName,
const CFileStatus& status);
DWORD SeekToEnd();
void SeekToBegin();
// backward compatible ReadHuge and WriteHuge
DWORD ReadHuge(void* lpBuffer, DWORD dwCount);
void WriteHuge(const void* lpBuffer, DWORD dwCount);
// Overridables
virtual CFile* Duplicate() const;
virtual LONG Seek(LONG lOff, UINT nFrom);
virtual void SetLength(DWORD dwNewLen);
virtual DWORD GetLength() const;
virtual UINT Read(void* lpBuf, UINT nCount);
virtual void Write(const void* lpBuf, UINT nCount);
virtual void LockRange(DWORD dwPos, DWORD dwCount);
virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
virtual void Abort();
virtual void Flush();
virtual void Close();
// Implementation
public:
virtual ~CFile();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
enum BufferCommand { bufferRead, bufferWrite, bufferCommit, bufferCheck };
virtual UINT GetBufferPtr(UINT nCommand, UINT nCount = 0,
void** ppBufStart = NULL, void** ppBufMax = NULL);
protected:
BOOL m_bCloseOnDelete;
CString m_strFileName;
};
偷懒点可以不用CFile,用
int fclose (FILE *stream);
int fflush (FILE *stream);
int fgetc (FILE *stream);
int fgetpos (FILE *stream, fpos_t *pos);
char *fgets (char *s, int n, FILE *stream);
FILE *fopen (const char *path, const char *mode);
int fprintf (FILE *stream, const char *format, ...);
int fputc (int c, FILE *stream);
int fputs (const char *s, FILE *stream);
size_t fread (void *ptr, size_t size, size_t n, FILE *stream);
FILE *freopen (const char *path, const char *mode,
FILE *stream);
int fscanf (FILE *stream, const char *format, ...);
int fseek (FILE *stream, long offset, int whence);
int fsetpos (FILE *stream, const fpos_t *pos);
long ftell (FILE *stream);
[此贴子已经被作者于2006-6-10 8:24:58编辑过]