Copyright: Version 4.0


Owner Draw Controls Component: Overview
Owner-Draw Control Component: Overview

The Owner-Draw Control component adds either an owner-draw list box or an owner-draw combo box to your project.

This new owner-draw control can then be used in any dialog box or window of your application.

•	Owner-Draw Control Component: Specifics

•	Owner-Draw Control Component: Results


Owner Draw Controls Component: Specifics
Owner-Draw Control Component: Specifics

The Owner-Draw Control component consists of two dialogs: Owner-Draw Control Component (used for selecting the type of control and changing the base name of the control class) and Change Files (used to change the header and implementation files of the control class). For more information on these dialogs, see Owner-Draw Control Component and Change Files.

Once you have chosen which type of owner-draw control to insert and the names of the header and implementation files, choose the OK button to insert an owner-draw control into your current project.

Note that switching control types resets all values to their defaults.

For more information on the exact changes made to your project, see Owner-Draw Control Component: Results.


Owner Draw Controls Component: Results
Owner-Draw Control Component: Results

The following changes are implemented in your project upon successful insertion of the component:

•	A new class that implements either an owner-draw list box or owner-draw combo box.

The header and implementation files for this class are discussed below.

•	The header (.H) file of the new class.

including directions on how to hook the new control up to the rest of the user's project.  (Directions also include how to tweak resources appropriately to make the new control work as expected.)

•	The implementation (.CPP) file of the new class.

All overridable list box/combo box functions have been overridden to give you an idea of how this is done.

Note that there is no direct connection between the new materials added and existing materials in your project. This means that to use this new class, you must declare an instance of it in your project. A common example would be to declare a member variable (of the new control class type) in a dialog class of your application that uses a list box or combo box.


Document Template Wizard Component: Overview
Document Template Component: Overview

In MFC, a document template is a combination of a document, view, and frame class and several resources.

The Document Template component adds a document template to your project, with these features: a document and view class, a menu, an icon, and template initialization in the InitInstance of your application class. Extra functionality is also available in the form of metafile and picture (bitmap) doc/view class pairs.

•	Document Template Component: Specifics

•	Document Template Component: Results


Document Template Wizard Component: Specifics
Document Template Component: Specifics

The Document Template Component adds a document template, with several features, to your project. You have the option of specifying what kind of document and view class to use, including your preference for an appropriate base class. You can also set up the document template string in a manner similar to that of AppWizard. Note that no Macintosh-specific resource manipulation is provided, so you will need to modify the Macintosh resource file (typically PRJNAME.R, where PRJNAME is the name of your project) to include Macintosh-style resource declarations for the new document type and icon. A default AppWizard document icon and view menu are also provided with the template.

In addition to the CDocument- and CView-derived classes, you can also choose document/view pairs that are designed for metafile or picture (bitmap) manipulation.

•	Metafile manipulation (CMetaFileDoc/View)

These classes are intended to be used as a pair. The class CMetaFileDoc provides basic support for opening and closing metafile documents. The class CMetaFileView provides basic support for playing metafiles in the client area of the view window. The level of metafile support present is sufficient to provide a base for writing your own metafile player, but is not a full-bodied implementation.

•	Picture manipulation (CPictureDoc/View)

These classes are intended to be used as a pair. The class CPictureDoc provides palette manipulation code as well as support for opening and closing DIB files. No support is provided for editing or saving DIB files. The class CPictureView provides bitmap drawing code and handles palette changes.

The initialization of the document template depends on the layout of your project. In other words, a single document interface (SDI) project will get an SDI initialization, and a multiple document interface (MDI) project will get an MDI initialization. The only requirement for this component is that you have both  a CWinApp-derived and a CFrame-derived class in your project. These classes are already present if you started with an AppWizard project.

The process for inserting the component is as follows:

Start by choosing the class for the document-portion of your template. You can choose any CDocument-derived class (including any in the current project), a metafile viewer document class, a picture viewer document class, or a new class. If you choose to create a new document class, you will use ClassWizard’s Add Class dialog.

Next, choose the class for the view-portion of your template. You can choose any CView-derived class (including any in the current project), a metafile viewer view class, a picture viewer view class, or a new class. If you choose to create a new view class, you will use ClassWizard’s Add Class dialog.

Finally, set up the resources for your document/view template. It is possible to choose a document template ID and modify the actual document template string later. However, if you want to be able to handle most of it in a more human-readable fashion, you will probably want to edit the document template string in the Properties... dialog associated with the document template ID. For some class types, default field values are available. For most class types, you must set up most of the document template string yourself. At this point, you also choose which frame class you want associated with your new document template. Your choices here depend on whether your application is SDI or MDI. If you have an SDI application, then your choices include all CFrameWnd-derived classes in your project. If you have an MDI project, then your choices include CMDIChildWnd and any classes derived from CMDIChildWnd in your project.


Document Template Wizard Component: Results
Document Template Component: Results

The following changes are implemented in your project upon successful insertion of the component:

•	A document class, if one was requested.

Note that a new document class is not created if the user chooses a common MFC class or an existing class in the project.

•	A view class, if one was requested.

Note that a new view class is not created if the user chooses a common MFC class or an existing class in the project.

•	Several resources, composed of the following: a menu, an icon, and a document template string with the document template ID requested by the user.

You will need to modify the new document template string and menu by replacing 'This Application' with the real name of your application.

•	A member variable of the appropriate type (CMultiDocTemplate* or CSingleDocTemplate*) to your CWinApp-derived class.

If you have two such classes, it gets added to the first one in the project.

•	The initialization of the new member variable in the user's CWinApp-derived class's InitInstance.

•	General instructions on modifying any Macintosh resources to use the new document template.


Persistent Window Placement Component: Overview

The Persistent Window Placement component adds the ability to save the position of the application's main window when the application is closed. When the application is next loaded, the main window is placed at the last saved position.

•	Persistent Window Placement Component: Specifics

•	Persistent Window Placement Component: Results


Persistent Window Placement Component: Specifics

When you insert this component, you will be given a list of all the CMDIFrameWnd-(the first preference) or CFrameWnd-derived classes in your project. When you have selected the class you want to add this feature to and chosen the Next button, you will be given a summary of the operations that will be performed by the component. Choosing the Finish button will complete the insertion.

Once the Persistent Window Placement component is successfully inserted, your application can do the following:

•	When the application terminates, the position of its main window frame is saved in the registry database.

•	When the application is next loaded, this information is retrieved from the registry database and the application's main window is repositioned accordingly.


Persistent Window Placement Component: Results

The following changes are implemented in your project upon successful insertion of the component:

•	Two member functions, LoadWindowPlacement and SaveWindowPlacement, are added to the selected class.

These functions will save and restore the window's position from the registry database.

•	Two message handlers, called OnCreate and OnClose, are added to the message map of the selected class.

These handlers call the appropriate member function, either to save or restore the position, during the launching and closing of the application.


Pop Up-Menu Component: Overview
Pop-Up Menu Component: Overview

The Pop-Up Menu component adds a pop-up menu to a CWnd-derived class in your project. When the user clicks with the right-mouse button on a window of this class, a menu appears. This menu initially contains the items "Cut", "Copy" and "Paste.” Note that no code is attached to these menu items. They are used to demonstrate the existence of the pop-up menu.

Note   This component will not work on Macintosh platforms.

After you have inserted this component, you add items to this menu and create handlers for these menu items using the resource editor and ClassWizard.

•	Pop-Up Menu Component: Specifics

•	Pop-Up Menu Component: Results


Pop Up-Menu Component: Specifics
Pop-Up Menu Component: Specifics

The Popup-Menu Component adds a popup menu, implemented with a CWnd-derived class, to your application. In addition, a sample menu with the entries "Cut", Copy" and "Paste" and a message handler (called OnContextHandler) for this menu are added to the project.

When you insert this component you will be shown a list of CWnd-derived classes in your project. Select the desired class, and choose the Next button. You will then be given a suggested name for the ID of the new menu resource, which you can change. Choosing the Finish button completes the insertion.


Pop Up-Menu Component: Results
Pop-Up Menu Component: Results

The following changes are implemented in your project upon successful insertion of the component:

•	A message handler, called OnContextMenu, for the selected CWnd-derived class.

This message handler handles the notification for the pop-up menu.

•	A CWnd-derived class that implements the pop-up menu.

•	A sample menu with three entries; "Cut", Copy" and "Paste."

This menu is for example only; the menu items are not active and need to be modified for your application’s needs.

•	A resource ID for the pop-up menu.

This resource ID is used to access the menu resource when creating the menu.


Property Sheets Wizard Component: Overview
Property Sheet Component: Overview

The Property Sheet component adds a property sheet or wizard-type property sheet to an existing project.

For more information on these types, see Property Sheet Component: Specifics and Property Sheet Component: Results.


Property Sheets Wizard Component: Specifics
Property Sheet Component: Specifics

The Property Sheet component adds a property sheet, or wizard (a modal dialog box that guides you through a difficult or complex task), to an existing project. For more information on wizards, see the CPropertyPage class overview in the Class Library Reference.

The Property Sheet component offers several variations of property sheets to choose from. However, because wizards are designed for completing or guiding the user through a difficult task, they are always modal. An optional preview window is also available. If you choose to add the preview window, the code needed to render the preview window is is already implemented. In every case, you get a custom property sheet class and up to nine scratch property pages.

The first page of the Property Sheet component lets you choose whether you want a property sheet or a wizard. For this component to insert successfully, it assumes that you have something derived from CCmdTarget in your project. This is required because the component needs classes derived from CCmdTarget to attach your new property sheet to. If the project was created using AppWizard, at least one CCmdTarget-derived class will be available. The next step is to choose whether your property sheet supports previewing. If you are creating a property sheet instead of a wizard, you also choose whether or not your property sheet is modeless. If you create a modeless property sheet, a mini-frame for the property sheet will be provided for you. After the preview step you choose the class you want to attach the new property sheet or wizard to and the number of property pages in your property sheet. Finally, you enter the names of the classes to be created and the file names they'll be written to.

The following choices for property sheets are available:

•	Custom property sheet (with all choices)

A property sheet, derived from CPropertySheet, with 1-9 property pages, derived from CPropertyPage. Initialization of the property sheet occurs in the property sheet’s constructor.

•	Property sheet with preview (if preview attribute is chosen)

A property sheet, derived from CPropertySheet, with 1-9 property pages, derived from CPropertyPage, and a preview window, derived from CWnd. Initialization of the property sheet occurs in the property sheet constructor. The preview window is initialized in the property sheet's OnInitDialog function.

•	Modeless property sheet (if modeless attribute is chosen)

A property sheet, derived from CPropertySheet, with 1-9 property pages, derived from CPropertyPage, and a mini-frame window, derived from CMiniFrameWnd. This property sheet is contained within a modeless frame unlike standard property sheets. Initialization of the property sheet occurs in the property sheet’s constructor. The property sheet is initializaed in the modeless frame's OnCreate function.


Property Sheets Wizard Component: Results
Property Sheet Component: Results

Note that the property sheet can't be invoked from your user interface after a successful insertion. For information on the steps needed to do this, see the comment in the OnProperties function (or OnWizards for wizards), added by the component.

The following items are inserted by this component for all variants of the property sheet:

•	A new custom property sheet class derived from CPropertySheet. The class and file names are determined by you.

•	The desired number of property pages and corresponding dialog templates.

The dialog template ID’s for the property pages are based on IDD_PROPSHT. When this component is inserted the first time, the ID’s will be IDD_PROPSHT1, IDD_PROPSHT2, etc. If the component is added to the project a second time, interesting template IDs, like IDD_PROPSHT22 (the second template of the second insertion), are created

Based on the options selected by you, the following items can also be inserted. If you choose:

•	Wizard

The new property sheet is set up as a wizard. This means that the property sheet is modal and contains a series of property pages that can only be viewed in a sequential order.

•	Supports Previewing

•	A preview window class gets added to the user's project

The preview window class is derived from Cwnd and the class and file names are chosen by you. This class is also linked to the property sheet created by this component.

•	Code to setup and manipulate the preview window is added to the new property sheet class.

•	Modeless (non-wizard)

•	A mini-frame class, derived from CMiniFrameWnd, is added to the user's project.

•	A pointer to the mini-frame class is added to the attaching class's member variable list.

•	The pointer to the mini-frame class is initialized in the attached class's constructor. Comments are provided in OnProperties to handle a non-default constructor case.

•	The mini-frame is initialized and called from the inserted OnProperties function in the attaching class.

•	A function, OnProperties (or OnWizards for a wizard) is added to the attaching class, the default class being CMainFrame, to set up the property sheet. This function mainly consists of comments describing what needs to be done and comes in two types:

1.	CUSTOM    This function creates a variable of the custom property sheet type, and then invokes the property sheet.

1.	MODELESS    This function, if needed, initializes a modeless property sheet frame declared in a member variable (variant on m_pFramePointer). After initializing the property sheet frame, this function calls the custom property sheet.

•	The appropriate initialization of the property sheet done in the CPropertySheet-derived class.


Owner Draw Controls Component
Owner-Draw Control Component

Use the Owner-Draw Control Component dialog box to select the type of owner-draw control to insert and the base name of the class that implements the control to be inserted.

Control Type
Choose the type of owner-draw control to insert; either list box or combo box.

Name
Use this control to change the name of the class that implements the owner-draw control.

Base Class
The name of the base class of the owner-draw control class; either CListBox or CComboBox.

File
Name of the implementation file for the owner-draw control.

Change...
Press this button to change the name of the header and implementation file for the control class.


Change Files

Use the Change Files dialog box to change the name of the header and implementation files of the owner-draw control class.

Header file
Use this control to change the name of the control’s header file.

Implementation file
Use this control to change the name of the control’s implementation file.

Browse...
Displays a dialog box for selecting a new drive and/or directory for the location of the header or implementation file.


Property Sheets Wizard
Property Sheet: Step 1 of 5

Use this dialog box to insert a property sheet or a wizard.

For more information on wizards, see the CPropertyPage class overview in the Class Library Reference.

Property Sheet
Inserts a property sheet into the project.

Wizard
Inserts a wizard into the project.


Property Sheets Wizard
Property Sheet: Step 2 of 5

Use this dialog box to choose the options of your property sheet.

Support previewing
Allows your property sheet to have a preview window. This window can display pictures or diagrams.

Property sheet modality
Determines if the property sheet will be modeless or modal.


Property Sheets Wizard
Property Sheet: Step 2 of 5

Use this dialog box to choose the options of your wizard.

Support previewing
Allows your wizard to have a preview window. This window can display pictures or diagrams depending on the user’s choices.


Property Sheets Wizard
Property Sheet: Step 3 of 5

Use this dialog box to choose the class the property sheet (or wizard) will be attached to.

Class name
Use this control to choose a class in your project to attach the property sheet (or wizard) to.


Property Sheets Wizard
Property Sheet: Step 4 of 5

Use this dialog box to choose the number of pages in your property sheet (or wizard).

Number of pages
Use this control to choose the number of pages for the property sheet (or wizard).


Property Sheets Wizard
Property Sheet: Step 5 of 5

Use this dialog box to view the properties of each new property page class in your property sheet (or wizard).

Class Name
Use this control to select the class whose properties you wish to view.

Change...
Press this button to change the name of the header and implementation file for the selected class.


Class Information
Change Class

Use the Change Class dialog box to view the class name and the header and implementation files for the new property sheet, mini-frame window, or preview window class.

Class Name
Use this control to change the name of the class that implements the property sheet, mini-frame window, or preview window class

Header File
The name of the header file for the new class.

Implementation File
The name of the implementation file for the new class.

Browse...
Displays a dialog box for selecting a new drive and/or directory for the location of the header or implementation file.


Document Class Page
Document/View Class Page

Use the Document Class Page dialog box to choose the document (or view) class to be used in the document template.

Existing Class
Use this control to choose the name of an existing class for the document template.

New Class
Use this control to add a new class to the project for the document template.

Properties...
Displays a dialog box for selecting various properties of the new class such as the name, the base class, and OLE Automation options.


Resource Page

Use the Resource Page dialog box to create the resources for the document template.

Resource Template ID
Use this control to enter the name of the resource ID for the document template.

Properties...
Displays a dialog box for selecting various properties of the new class such as the name, the file extension, and localized string values.

Associated Frame Class
Use this control to choose the name of an existing frame class in the project. The new template will be associated with this class.


Template Strings

Use the Template Strings dialog box to specify the filenames and extensions of the new document template, such as the file extension and description. You can also enter the values of the template’s localized strings such as the short and long OLE names, the filter name, and the document type name.

File Extension
Use this control to enter the file extension associated with a document created by the new document template. Entering a file extension allows the Windows 95 Explorer to print your application’s documents, without launching your application, when they are dropped on a printer icon.

File Type ID
Use this control to enter the ID used to label your document type in the system registry.

Doc Type Name
Use this control to enter the filename associated with the selected class. This option is available only if the selected class is derived from class CDocument.

Filter Name
Use this control to enter the string that appears in the List Files of Type list box in the Open and Save As dialog boxes. This field does nothing unless you type a file extension in the File Extension edit box.

File New Name
Use this control to enter the name that appears in the File New dialog box if there is more than one new document template. If your application is an OLE server, this name is used as the short name of your OLE object.

File Type Name
Use this control to enter the long name of your OLE object if your application is an OLE server. It is also used as the file type name in the system registry.


Persistent Window Placement

Use the Persistent Window Placement dialog box to select the desired class.

Select the Frame Class
Use this control to select the name of the class you wish to have persistent window placement.


Pop-up Menu

Use the Pop-up Menu dialog box to select the desired class.

Add pop-up menu to
Use this control to select the name of the class you wish to add the pop-up menu to.

Menu resource ID
Use this control to enter the resource ID for the pop-up menu to be added.