10.4 Opening an Existing File

You can open an existing file by using the OF_READ, OF_WRITE, or OF_READWRITE option in the OpenFile function. These options direct OpenFile to open existing files for reading, writing, or reading and writing. The following example opens the FILE.TXT file for reading:

hFile = OpenFile("FILE.TXT", &OfStruct, OF_READ);

If the file fails to open, you can display a dialog box to indicate that the file was not found. You can also use OpenFile to prompt for the file, as described in Section 10.7, “Prompting for a File.”