void CMy12View::OnFileWrite()
{
// TODO: Add your command handler code here
/*
char ch[]="ADFADAKLDJFKLANSDFA";
CFile file("1.txt",CFile::modeReadWrite|CFile::modeCreate);
file.Write(ch,sizeof(ch));
file.SeekToBegin();
*/
//句柄
/*
HANDLE hFile;
hFile=CreateFile("1.txt", GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL );
DWORD dwWrites;
WriteFile(hFile,"asdfasdfasdf",sizeof("asdfasdfasdf"),&dwWrites,NULL);
CloseHandle(hFile);
*/
}
void CMy12View::OnFileRead()
{
// TODO: Add your command handler code here
/*
BYTE buf[0x1000];
CFile file;
file.Open("1.txt",CFile::modeReadWrite);
DWORD dwBytesRemaining=file.GetLength();
while(dwBytesRemaining)
{
DWORD dwPosition=file.GetPosition();
UINT nByeteRead=file.Read(buf,sizeof(buf));
::CharLowerBuff((char *)buf,nByeteRead);
file.Seek(dwPosition,CFile::begin);
file.Write(buf,nByeteRead);
dwBytesRemaining=nByeteRead;
}
MessageBox((char *)buf);
file.Close();
*/
HANDLE hFile;
hFile=CreateFile("1.txt",GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
char chr[100];
memset(chr,0,sizeof(char)*100);//这一句写不写结果都一样
DWORD dwRead;
ReadFile(hFile,chr,100,&dwRead,NULL);
chr[dwRead]=0;
CloseHandle(hFile);
MessageBox(chr);
}
文件读写
最新推荐文章于 2024-03-28 09:00:00 发布