U E D R , A S I H C RSS

레밍즈프로젝트/프로토타입/파일스트림

대략적인 CFile

Data Members
m_hFile Usually contains the operating-system file handle.

Construction
CFile Constructs a CFile object from a path or file handle.
Abort Closes a file ignoring all warnings and errors.
Duplicate Constructs a duplicate object based on this file.
Open Safely opens a file with an error-testing option.
Close Closes a file and deletes the object.

Input/Output
Read Reads (unbuffered) data from a file at the current file position.
ReadHuge Can read more than 64K of (unbuffered) data from a file at the current file position. Obsolete in 32-bit programming. See Read.
Write Writes (unbuffered) data in a file to the current file position.
WriteHuge Can write more than 64K of (unbuffered) data in a file to the current file position. Obsolete in 32-bit programming. See Write.
Flush Flushes any data yet to be written.

Position
Seek Positions the current file pointer.
SeekToBegin Positions the current file pointer at the beginning of the file.
SeekToEnd Positions the current file pointer at the end of the file.
GetLength Retrieves the length of the file.
SetLength Changes the length of the file.

Locking
LockRange Locks a range of bytes in a file.
UnlockRange Unlocks a range of bytes in a file.

Status
GetPosition Retrieves the current file pointer.
GetStatus Retrieves the status of this open file.
GetFileName Retrieves the filename of the selected file.
GetFileTitle Retrieves the title of the selected file.
GetFilePath Retrieves the full file path of the selected file.
SetFilePath Sets the full file path of the selected file.

Static
Rename Renames the specified file (static function).
Remove Deletes the specified file (static function).
GetStatus Retrieves the status of the specified file (static, virtual function).
SetStatus Sets the status of the specified file (static, virtual function).

CFile Prototype

전화받아라 이승한-_-


#include "stdafx.h"
#include "FileioView.h"

void CFileioView::OnWritefile()
{
	CFile Wfile;
	if(!Wfile.Open("TestFile.txt", CFile::modeCreate | CFile::modeWrite))
	{
		::MessageBox(NULL, "Can't Create testfile.txt !", "Warning", MB_OK | MB_ICONHAND);
		return;
	}
	char* ps = new char[27];
	char* ps2 = ps;

	for(int i=0;i<26;i++)
		*ps2++ = 'A'+i;
	*ps2 = NULL;    // NULL 문자로 끝나게 한다.
	Wfile.Write(ps,27);
	Wfile.Close();
	delete ps;
}

void CFileioView::OnReadfile()
{
	CFile Rfile;
	if(!Rfile.Open("TestFile.txt", CFile::modeRead))
	{
		::MessageBox(NULL, "Can't Open testfile.txt !", "Warning",
                       MB_OK | MB_ICONHAND);
		return;
	}
	UINT FileLength = (UINT)Rfile.GetLength();

	char* ps = new char[FileLength];
	Rfile.Read(ps,FileLength);
	Rfile.Close();

	CPaintDC dc(this);
	dc.TextOut(0,0,ps,lstrlen(ps));
	delete ps;
}

파일 입출력 부분에 의해 "TestFile.txt"라는 파일을 만들고,
CFile 클래스 내의 Write() 함수를 이용해서 'A' ~ 'Z' 까지 써 넣는 함수 (OnWriteFile())와,
파일에 쓰여진 'A' ~ 'Z'까지 불러들여서 화면에 출력하는 함수 (OnReadFile()) 함수이다.

우선 기본적으로 레밍즈에서 맵을 제작하게 되면 맵을 저장하기 위해서
위의 OnWriteFile()에서 쓰여진 Open() 함수와 Write() 함수를 쓰게 될것 같다.
그리고 레밍즈 게임을 실행하게 되면 그 맵이 불려져야 하므로,
기본적인 Read() 함수도 사용할 것 같다.
그러나 실제 레밍즈 게임에서는 txt 파일 형식이 아니라 bitmap 형식으로의 저장과 읽기가 가능해야 하므로,
가상화면을 생성하고, 가상화면에 그린것을 화면으로 복사하고 , 가상화면을 지우는 작업등이 추가 되어야 한다.
그 나머지 과정은 일반적인 작업 내용은 거의 동일하므로 기본적인 CFile 부분을 숙지해야 할 것 같다.
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:22
Processing time 0.0386 sec