Last update Thu Jun 2 19:05:07 2011

4. Generating an Application Framework

This chapter introduces application frameworks and the steps necessary to generate and build on such a framework. This process uses two tools: AppExpress and ClassExpress.

Before reading this chapter, take look at the material in Starting a Project and Defining Workspaces in the IDDE. AppExpress creates both an application framework (according to specifications you provide) and the project in which that framework resides.

More about AppExpress and More about ClassExpress are the reference chapters for the AppExpress and ClassExpress tools.

What Is an Application Framework?

An application framework is a standardized skeleton architecture for an object-oriented application. The framework is composed of C++ classes derived from base classes in the Microsoft Foundation Class (MFC) library.

Using a framework to build an application dramatically shortens its development time. All the files needed to create the application are included in the skeleton program. Standard user interface components such as windows, menus, and toolbars are already defined. Some of the necessary connections between the defined C++ classes are established automatically.

With a framework as a starting point and using the MFC library, you can build many different types of applications by:

As you build application frameworks with AppExpress and ClassExpress, you will become familiar with message maps. Message maps summarize, within a data structure or table, all of the links between Windows messages and the methods (also called functions) of a particular class that process those messages. Each entry in a message map is a pair, consisting of a message identifier and a method that responds to that message. The method is said to handle the message. Methods referenced in message maps are also called message handlers, or simply handlers.

Because message maps are used by MFC to route Windows messages to the messages' handlers, they provide the essential translations needed to present the event-driven model of the Windows API in an object-oriented guise. By automating the creation and maintenance of message maps, AppExpress and ClassExpress relieve you of much error-prone drudgery, and allow you to spend more of your development time writing code that implements functionality.

The following sample message map was automatically generated by AppExpress for an MDI-style application framework:

    BEGIN_MESSAGE_MAP( CMainView, CView)
	//{{ AFX_MSG_MAP( CMainView) 
	// NOTE -ClassExpress will add and
	// remove mapping macros here. 
	// DO NOT EDIT what you see in these
	// blocks of generated code ! 
	// Standard printing commands 
		CView:: OnFilePrintPreview)

Creating a Framework with AppExpress

This section describes how to launch AppExpress and use it to generate an application framework.

Launching AppExpress

From the IDDE main window, choose AppExpress from the Tools menu. This opens the window shown in Figure 4-1.

[Figure 4-1 AppExpress window]

Looking at the AppExpress window

The AppExpress window contains: To navigate through the six pages of options, click on the name of a step in the steps list, or click on the Next or Previous button. Alternatively, press Control-n, where n is a number between 1 and 6 representing the selected step's position in the steps list.

Specifying an application framework

AppExpress divides the process of building a framework into six steps: These steps, which are briefly outlined here, do not have to be completed in this order. However, you will find it convenient to complete the first step specifying application type options before proceeding to any other step. All later steps contain some options that depend upon your choices in this step.

Selecting an application type

To select an application type:
  1. Select Application Type from the steps list in the AppExpress window.
  2. Select an application type by clicking on a radio button in the Applications group. There are six categories of applications, two of which SDI and MDI can be made OLE clients and/or servers.
Check the Include Help box if you want AppExpress to generate files from which a Windows help file can be created. Check the 32- Bit Project box if you are building a 32-bit application. See Chapter 17, "More about AppExpress" for the details of how the 32-Bit Project check box combines with the selected application type to determine what AppExpress generates.

Selecting application type options sets default options for many of the other steps in AppExpress. For example, if you select Dialog Box, AppExpress automatically creates three C++ classes with default class names in your skeleton program. You can change these defaults; for example, you can modify the default class names by selecting Names from the steps list.

Selecting a directory for the project

To select a directory for your source files and project file:
  1. Select the Select Directory item from the steps list. The Select Directory options page opens as shown in Figure 4-2.
  2. Select the appropriate drive and directory. Or, click on Create New Directory to create and name a new directory. AppExpress suggests the project name as the new directory name, but you may change that default.

    [Figure 4-2 Select Directory options]

Providing copyright information and project options

You can supply copyright information for your source code, and set the project's name, stack size, and heap size as follows:
  1. Select Miscellaneous from the steps list. The Miscellaneous options page opens as shown in Figure 4-3.

    [Figure 4-3 Miscellaneous options]

  2. Provide copyright information in the appropriate fields. AppExpress uses this information to write a copyright notice in the comment header of all of your application's source files, and to construct the application's About dialog box.
  3. Specify the project name in the appropriate field. Stack and heap sizes can be changed later in the Project Settings dialog box.

Specifying class names

To view and change the names of C++ classes or their associated source files:
  1. Select Names from the steps list. The Names options page opens as shown in Figure 4-4.
  2. In the options pane, select a class from the Name drop-down list automatically created by AppExpress. The class names included in this list depend on the application type you have selected.
  3. If you like, you can edit the selected class name. Note, however, that C++ class names follow a standardized naming convention. Using the default names allows your program's structure to be easily understood by others.
  4. In the appropriate field, type the names of the header and source files in which AppExpress should place the class source code.
Note: The CAboutDlg class, which represents your application's About Box class, is always created in the same header and implementation files as the CWinApp-derived class (for example, CSDIAPP).

To discard any changes you have made on this page, click on the Set Default Names button.

[Figure 4-4 Names options]

Naming source files

To edit filenames automatically generated by AppExpress:
  1. Select File Names from the steps list. The File Names options page opens as shown in Figure 4-5.
  2. In the options pane, click on the filename you want to change. The files listed depend on the application type you have selected. Their names correspond to their functionality within the application.
  3. Edit the filename, but remember that these changes could make it harder for someone else to identify the purpose of the file.

    [Figure 4-5 File Names options]

Specifying help file names

To view or change the names of the files that the help compiler uses to generate online help files for your application:
  1. Select Help Options from the steps list. The Help Options options page opens as shown in Figure 4-6.

    [Figure 4-6 Help Options options]

    Note If you selected Quick Console or Dialog Box as the application type, or if Include Help is not selected in the Application Type options page, then you have no help options.

  2. Edit the filenames if you want. Note, however, that any changes could make it harder for someone else to identify the purpose of the file.

Generating an application framework

At this point, you have selected an application type and the directory in which the application project files will reside, and you may have customized various class names or filenames. AppExpress can now generate your application framework in the form of a skeleton program.

Click on the Finish button in the AppExpress window. AppExpress generates the project and its source files, as you specified, hands it off to the project system, and closes.

Note If you checked the Include Help box among the Application Type options, then you will need to build the help file for your application. You do this by running the makehelp. bat file that AppExpress creates in your project directory.

Your skeleton program is ready. You can now build the program from within the IDDE, or you can add to your program by using other Digital Mars C++ tools. The next section shows how to enhance your application's C++ classes by using ClassExpress.

Building on a Framework with ClassExpress

AppExpress cuts the work involved at the beginning of the application-building process. ClassExpress, on the other hand, enhances productivity throughout the rest of the process. You use this tool to flesh out the skeleton application produced by AppExpress.

Specifically, you can use ClassExpress to:

This chapter describes the first two of these options: writing message maps and creating new classes derived from existing classes.

Message maps, defined in "What Is an Application Framework?" in this chapter, are discussed in greater detail in Chapter 17, "More about AppExpress."

You can use ClassExpress immediately after creating an application framework as well as at later points in development. For example, you probably want to wait until you have created some dialog boxes with ResourceStudio (see Chapter 7, "Adding Look and Feel with Resources" ) before mapping class member variables to user interface objects.

Launching ClassExpress

From the IDDE main menu, launch ClassExpress by choosing ClassExpress from the IDDE's Tools menu.

Launching ClassExpress opens the window shown in Figure 4-7.

[Figure 4-7 ClassExpress window]

Looking at the ClassExpress window

The ClassExpress window contains: To navigate through the selections, click on the name of a selection in the list. Alternatively, use the key combination Control-n, where n is a number between 1 and 6 representing the position in the selections list of the selection to which you want to move.

Writing a message map with ClassExpress

Message maps are tied to particular C++ classes. In ClassExpress, you can add to an existing message map by adding new linkages between messages and class methods. Or you can add a new message map for an entirely new class.

ClassExpress runs from within the IDDE or as a stand-alone application. If run from within the IDDE, ClassExpress will be loaded with the IDDE's open project if there is one; otherwise, it prompts to open an existing project (which also opens the project in the IDDE's project system).

As an example, the following steps demonstrate how to add a message handler to the CAboutDlg class of an SDI application generated by AppExpress:

  1. Select Message Maps from the listbox. (If you just started ClassExpress, this should already be selected.) The ClassExpress window is displayed as shown in Figure 4-7.
  2. Select the class CAboutDlg from the Class drop-down list. The contents of the three other lists in the options pane are updated to reflect the following selection:
    • Control IDs in Class: This list contains all of the menu links and control IDs for which this class can add handlers. For example, IDOK is a universally defined constant for an OK button. Because the CAboutDlg class includes an OK button by default, the IDOK constant is always predefined for this class.

      Because this class represents a dialog box- which itself can respond to many Windows messages- the first item in the Control IDs in Class list is the name of the class itself (CAboutDlg).

    • Windows Messages: This list contains all of the Windows messages that apply to the selected item in the Control IDs in Class list. For example, if you highlight IDOK in that list, two applicable messages (button notifications, in this case) are displayed in the Windows Messages list: BN_CLICKED and BN_DOUBLECLICKED. If a handler is defined for a message, a red box appears before the message name in this list.
    • Function Name: This list contains all of the handlers that exist within the selected class. These are the methods that are linked to Windows messages.
  3. Select CAboutDlg from the Control IDs in Class list. The list of Windows messages changes, revealing a long list of messages to which your dialog box could respond.
  4. Double-click on WM_ACTIVATE. Notice that the method OnActivate (in its fully prototyped form) is added to the Function Name list.
Now, whenever your About dialog is activated, the OnActivate method is called in response to the dialog window receiving the message WM_ACTIVATE. With the four above steps, you have created an association between the message WM_ACTIVATE and the method OnActivate, and added it to the message map for the CAboutDlg class.

Adding a new class to your application

Adding new classes to your application is as easy as creating a message map. To add a class:
  1. Select Message Maps from the listbox. (If you just loaded ClassExpress, then this should already be selected.)
  2. Click on the Add Class button. The Add Class dialog box shown in Figure 4-8 opens.

    [Figure 4-8 Add Class dialog box]

  3. Select a class type from the Class Type drop-down list. This type specifies the base class from which your new class will be derived. The list displays names of MFC classes without the initial letter 'C', thereby allowing you to navigate rapidly within the list by typing the first letter of a class type. For example, typing 'V' selects the View class type.
  4. The New Class Name field becomes active, displaying a suggested name for the new class. Edit this name as appropriate.
  5. If you selected CDialog or CFormView, then the field Dialog ID is displayed. Move to this field and choose the resource ID of the dialog that you want to associate with the new class's window.
  6. Check the OLE Automation box if you want your new class to be a programmable OLE object. If you choose this option, any other Windows application that is an automation client can use the OLE interface you define for this object.
  7. If you check the OLE Automation box and you are deriving a new class from the CCmdTarget or CWnd class, the Creatable check box is displayed. Check this box if you want other applications to be able to create the OLE automation object that you are defining.
  8. If you check the OLE Automation check box and you are deriving a new class from the CCmdTarget or CWnd class, you must also type a name in the External Name field. This is the name that is exposed to other applications that may want to use your OLE automation object.
  9. Decide whether to edit the implementation filename of your new class (shown in the last field in the Add Class dialog box). By default, the base part of the filename is the name of your new class without the initial letter 'C', and truncated if necessary.
  10. Click OK to add the new C++ class to your application. If you want, you can create message mappings for your new class by using the steps outlined in the previous section.
This section on ClassExpress showed how easy it is to write a message map and to create a new class. By just clicking on a check box, you can also add OLE automation support to your application.

In addition, ClassExpress can bind your classes to your dialog boxes and generate C++ wrapper classes for Visual Basic custom controls (VBXs). It also provides extensive support for building OLE servers and containers. For more information on these features, refer to Chapter 18, "More about ClassExpress."

Home | Compiler & Tools | Runtime Library | STL | Search | Download | Forums | Prev | Next