A Simple File Editor: EditFile

This example shows how to create a simple Windows application that uses the OpenFile and C run-time functions to open and save small text files. To create the EditFile sample application, copy and rename the FileOpen application sources, described in Chapter 21, “Dialog Boxes,” and modify them as follows:

1.Add constants to the include file.

2.Create a SaveAs dialog-box template and add it to the resource script file.

3.Add new include statements to the C-language source file.

4.Add new variables.

5.Replace the WM_COMMAND case.

6.Add the WM_QUERYENDSESSION and WM_CLOSE cases.

7.Modify the OpenDlg dialog function.

8.Create a SaveAsDlg dialog function.

9.Create helper functions for the SaveAsDlg dialog function.

10.Export the SaveAsDlg dialog function.

11.Modify the application's HEAPSIZE statement.

12.Build and run the application.

When this application is completed, you will be able to view text files in an edit control. The application's Open command in the File menu will let you specify the file to be opened. You will also be able to make changes to a file or enter new text, and save the text using the Save or Save As command in the dialog box.

NOTE:

Rather than typing the code provided in the following sections, you might find it more convenient to simply examine and build the sample source files provided on the sample disks.