![]() |
File Processing: Archiving |
|
Introduction to File Processing |
File processing is the ability to create, store, and/or retrieve the contents of a file from a medium such as a hard drive, a floppy disk, a CD-ROM, or a DVD-ROM, etc. One of the areas in which the MFC excels is file processing. MFC makes it particularly easy to perform most file related operations.
Before creating a file, you should first plan your program since applications deal with different types of files. An application that manipulate pictures may need to save only one value for the whole file. Another application used for word processing may also need to save only one value but of a completely different kind. If an application is list-based, it may need to save various values that, when put together, constitute one file. |
|
After deciding what type of file the user would be processing, you would also specify how and/or who would decide when to process a file. For example, if you create a certain application that allows a user to change the internal settings and store them in a file, you can process the file automatically and store it somewhere without asking the user to decide when, where, or how to save the file (some applications use the Registry to take care of this). For example, in tthe bits of data that are arranged in a particular way to produce a usable document. For easy storage, location, and management, the bits are stored on a medium such as a hard disc, a floppy disc, a compact disc, or any valid and support type of storage. When these bits belong to a single but common entity, the group is referred to as a file. For even greater management, files can be stored in a parent object called a directory or a folder. Since a file is a unit of storage and it stores information, it has a size which is the number of bits it contains. To manage it, a file also has a location also called a path that specifies where and/or how the file can be retrieved. Also, for better management, a file has attributes that indicate what can be done on a file or that provide specific information that the programmer or the operating system can use when dealing with the file.
|
|
The Process of Archiving |
|
One of the most regular ways you will use the CArchive class consists of storing or retrieving values through their Serialize() method. To do this directly and easily in the class, the CArchive class overloads two operations: << and >>. To store one or more values, the CArchive class provides the << operator. The values you can store are of MFC, BYTE, short, WORD, int, unsigned int, long, LONG, DWORD, float, or double types. The class also provides an exception handler for each kind. Therefore, the syntaxes for this operator are:
As you may have realized, there is only one version of the Serialize() method. That is, this member function is called once for both storing and retrieving. Therefore, when using it, you must specify what operation you want to perform. This checking process can be performed by calling the CArchive::IsStoring() Boolean method. Its syntax is: BOOL IsStoring() const; This method returns TRUE if you are storing data. If the answer is then TRUE, you can use the << operator to store each necessary value. As opposed to storing value(s), to retrieve a value, the CArchive class provides the >> operator. It comes in the following syntaxes:
This indicates that you can retrieve an MFC object, a BYTE, a short, a WORD, an int, an unsigned int, a long, a LONG, a DWORD, a float, or a double value. As mentioned above, the Serialize() method is used for both operations. Therefore, when using this method, you should first check what operation is being performed. This can be done by calling the IsLoading() method. Its syntax is: BOOL IsLoading() const; This method returns TRUE if you are retrieving a value or some values. If it is true, you can then use the >> operator to retrieve the value(s). |
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
MFC Support of File Processing |
|
Introduction |
|
MFC supports file processing at different levels. There is so much file processing that one of your biggest difficulties would consist of deciding what file processing system you want to use. MFC supports C, C++, Win32, and MFC file processing. Even if you select only one of these categories, some of them have other variances. For example, the C++ language provides more than one way to perform file processing. MFC itself is tremendously wide on this issue. One of the classes used to perform file processing on MFC applications is CFile. Using this class, to create a file, you can first declare a variable of type CFile using one of its 3 constructors. They are; CFile( ); CFile( int hFile ); CFile( LPCTSTR lpszFileName, UINT nOpenFlags ); The default constructor is used if you are not ready to specify the information needed to create the file. The second constructor takes an argument that is a handle to a file created using the Win32's CreateFile() function. The third constructor is used to create a file by specifying the file name and the flags that specify the operation to perform when saving or opening the file. |
|
Automatic File Processing |
|
Automatic File Processing consists of saving or opening a file with little to no intervention from the user. This technique is used to provide values that should be automatically provided to the user. This technique also allows the user to create or add a new value to a list that is deemed incomplete. |
|
|
|
|
|
|
| Home | Copyright © 2004-2005 FunctionX, Inc. |
|
|
|