📄 cfile.hpp
字号:
#ifndef _CFILE_HPP
#define _CFILE_HPP
#include <windows.h>
#include <tchar.h> // Make all functions UNICODE safe.
#include "CMemory.hpp"
#include "CString.hpp"
class CFile {
public:
typedef enum {
Normal,
RdOnly,
Shared
} Mode;
protected:
HANDLE handle; // Handle al CFile
BOOL WasCreatd; // Flag para indicar si se creo el archivo
public:
CFile() : WasCreatd(FALSE) , handle(INVALID_HANDLE_VALUE) {}
CFile(LPTSTR File,Mode CMode = Normal,DWORD Beh = OPEN_ALWAYS)
: WasCreatd(FALSE) , handle(INVALID_HANDLE_VALUE)
{
Open(File,CMode,Beh);
}
CFile(CString& File,Mode CMode = Normal,DWORD Beh = OPEN_ALWAYS)
: WasCreatd(FALSE) , handle(INVALID_HANDLE_VALUE)
{
Open(File,CMode,Beh);
}
bool Open(LPTSTR File,Mode CMode = Normal,DWORD Beh = OPEN_ALWAYS);
bool Open(CString& File,Mode CMode = Normal,DWORD Beh = OPEN_ALWAYS) { return Open(File.Ptr(),CMode,Beh); }
bool IsOpen() const { return (handle!=INVALID_HANDLE_VALUE); }
bool WasCreated() const { return WasCreatd==TRUE; }
bool Close();
bool Read(void* Buffer,DWORD Bytes) {
DWORD BytesRd=0;
return (ReadFile(handle,Buffer,Bytes,&BytesRd,NULL) && (BytesRd==Bytes) );
}
bool Read(void* Buffer,DWORD Bytes,DWORD& BytesRd) {
BytesRd=0;
return (ReadFile(handle,Buffer,Bytes,&BytesRd,NULL) && (BytesRd==Bytes) );
}
bool Write(void* Buffer,DWORD Bytes) {
DWORD BytesWr=0;
return (WriteFile(handle,Buffer,Bytes,&BytesWr,NULL) && (BytesWr==Bytes) );
}
bool Write(CMemory& blk) {
DWORD BytesWr=0;
return (WriteFile(handle,blk.Ptr(),blk.Size(),&BytesWr,NULL) && (BytesWr==blk.Size()) );
}
DWORD Seek(LONG Dist,DWORD MvMt=SEEK_SET) {
return SetFilePointer(handle,Dist,NULL,MvMt);
}
bool Lock(DWORD Foff,DWORD Sz) {
return LockFile(handle,Foff,0,Sz,0)==TRUE;
}
bool Unlock(DWORD Foff,DWORD Sz) {
return UnlockFile(handle,Foff,0,Sz,0)==TRUE;
}
DWORD Size() {
return GetFileSize(handle,NULL);
}
bool SetSize(DWORD Size);
DWORD Pos() {
return Seek(0,SEEK_CUR);
}
bool Flush() {
return FlushFileBuffers(handle)==TRUE;
}
~CFile() {
Close();
}
};
// Some filenames related fns
// Wild matching function
bool Wild(LPTSTR pattern, LPTSTR string);
// Get Windows directory
CString GetWindowsDirectory();
// Get Temp directory
CString GetTempDirectory();
// To Delete files
bool DeleteFile(CString& c);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -