SAMPLE: Property Sheet as the View Window of a CFrameWnd

ID: Q161886


The information in this article applies to:


SUMMARY

The Psview.exe sample illustrates a technique of having a PropertySheet- like view inside a CFrameWnd-derived class.

The following file is available for download from the Microsoft Software Library:

~ Psview.exe
For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services
NOTE: Use the -d option when running Psview.exe to decompress the file and recreate the proper directory structure.


MORE INFORMATION

The PropertySheet-like view is a window that has the look of PropertySheet. It contains a row of tabs; clicking each tab will load the appropriate page (or dialog template).

NOTE: This article does not make use of either the Property Sheet or the Property Pages like the SNAPVW sample. Because of this, the frame window that contains the PropertySheet-like view can be resized as it normally would. However, controls inside a page (or dialog template) need to be moved manually to fit the page as they appear in a regular dialog box.

The picture below shows the general layout of the frame window when it is first running:

CFrameWnd-derived class


    +---------------------------------------------------+
    | +-----------------------------------------------+ |
    | |         CToolBar class                        | |
    | +-----------------------------------------------+ |
    | +-----------------------------------------------+<----+
    | |         CTabCtrl class                        | |   |
    | |-----------------------------------------------| |   |
    | |                                               | |   |
    | |                                               | |   |
    | |         CDialog-derived class                 | |   |-- CView-derived
    | |         (a child of CTabCtrl class)           | |   |   class
    | |                                               | |   |
    | |                                               | |   |
    | |                                               | |   |
    | +-----------------------------------------------+<----+
    | +-----------------------------------------------+ |
    | |         CStatusBar class                      | |
    | +-----------------------------------------------+ |
    +---------------------------------------------------+ 
As the picture shows, a frame window (CFrameWnd-derived class) contains the following child windows: The view window has tab control (CTabCtrl) as its child window, and tab control has one or more modeless dialog boxes (CDialog-derived class) as its child windows. In other words, the tab control will occupy the whole client area of the view window and the modeless dialog boxes (or pages) will occupy the display rectangle inside the tab control. However, there can be only one page visible at any given time.

For simplicity, all pages in the sample code are created after the tab control is successfully created in the view window. (The code for page creation can be found in the CreatePages() function in tabview.cpp file.) These pages will not be destroyed until the application shuts down. When the view window receives the input focus (when the application is first running), the page for the first tab will be the visible page in the display area of the tab control.

Whenever a tab is selected from the tab control, both TCN_SELCHANGING and TCN_SELCHANGE notification codes will be sent to the parent window (the CView-derived class). The first notification code is to notify the parent window that the currently selected tab is about to change. It is a good place to put code to hide the currently visible page. On the other hand, displaying the newly-selected page may be handled in the second notification code.

The following list shows the general steps to have a PropertySheet-like view in an AppWizard-generated application:

  1. Create all pages (or dialog boxes) for the tab control in dialog resource editor. Each page has a caption (for the tab text), a child style, and a thin border.


  2. Create the header and implementation files for all pages (or dialog boxes) using ClassWizard.


  3. Make the following changes to the header file (.h) of your CView-derived class:



  4. Make the following changes to the implementation file (.cpp) of your CView-derived class:



  5. Use ClassWizard to add the PreTranslateMessage() function to your CWinApp-derived class. In the body of this function, call the view's HandleKeyDownMsg() function so it gets a chance to handle any keystroke messages that are relevant to its tab control. For messages that are not handled by the view, pass them to the default handler. Please refer to the sample PreTranslateMessage() in psview.cpp file.


The Readme.txt file included with the sample explains in more detail how the sample is created in AppWizard and what files are included.


REFERENCES

Please refer to Visual C++ Books for information about the classes mentioned in the article and ClassWizard usage for creating .h and .cpp files for all pages.


Keywords          : kbcode kbfile kbsample kbDocView kbMFC kbVC 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: July 12, 1999