Auto Property Sheet in FormView | CodeGuru

Auto Property Sheet in FormView

This project provides derived MFC classes for painlessly implementing Property Sheets in a CFormViews.  This implementation puts the Property Sheet at the bottom of the view as shown in the following image: Four derived MFC classes are used in this implementation. CPropPgFormView: a CFormView derived class. CPropPgFormDoc: a CDocument derived class. CViewPropertyPage: a CPropertyPage derived […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 11, 1999
3 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This project provides derived MFC classes for painlessly implementing Property Sheets
in a CFormViews.  This implementation puts the Property Sheet at the bottom of the
view as shown in the following image:

wpe1.jpg (14545 bytes)

Four derived MFC classes are used in this implementation.

  • CPropPgFormView: a CFormView derived class.
  • CPropPgFormDoc: a CDocument derived class.
  • CViewPropertyPage: a CPropertyPage derived class.
  • CViewPropertySheet: a CPropertySheet derived class.

The property sheet is managed by CPropPgFormView, moving the sheet below the
template-based controls of the CFormView derived class.  Resizing the frame resizes
the Property Sheet accordingly.

What CPropPgFormView gives you:

  • Scrolling sizes are managed for you.
  • Tab order is enabled across the CFormView controls and the Property Sheet.
  • Hotkeys work for the page tabs.
  • Page changing can be disabled.
  • Property page controls can be disabled.
  • Auto-centering of controls within each property page.
  • Adjustable distance between the bottom-most template-based control and the Property
    Sheet.
  • Form notification of page activation

To use these classes, follow these steps:

  • Base your property pages on CViewPropertyPage instead of CPropertyPage.
  • Base your form view class from CPropPgFormView instead of CFormView.
  • Register the document template with the correct classes in your apps InitInstance():
        CMultiDocTemplate*
    pDocTemplate;
        pDocTemplate = new CMultiDocTemplate(
            IDR_SHEETITYPE,
            RUNTIME_CLASS(CPropPgFormDoc),
            RUNTIME_CLASS(CChildFrame),
            RUNTIME_CLASS(CMyFormView));
        
    // your
    CPropPgFormView class

        AddDocTemplate(pDocTemplate);
  • Add the property pages in your view’s Create() and create the sheet:.
    BOOL CMyFormView::Create(LPCTSTR lpszClassName, LPCTSTR
    lpszWindowName,
      DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext*
    pContext)
    {
    if (!CPropPgFormView::Create(lpszClassName, lpszWindowName,
       dwStyle, rect, pParentWnd, nID, pContext))
    return FALSE;

    m_PropSheet.AddPage(&m_Page1);
    m_PropSheet.AddPage(&m_Page2);
    m_PropSheet.AddPage(&m_Page3);

    // create a modeless property sheet
    if (!m_PropSheet.Create(this)) {
    DestroyWindow();
    return FALSE;
    }

    return TRUE;
    }

… and that’s it.

 

Methods and members:

CPropPgFormView
void ResizeForNewControl() – resizes the Property Sheets after programmatically
adding new controls
void SetPropertySheetOffset(int iOffset  = PS_Y_OFFSET, BOOL bRedraw  =
FALSE)
– sets distance between bottom-most form control and top of the Property Sheet
void ResizeParentFrame() – resizes frame window to most efficiently encompass all
controls and Property Sheet, and sets scroll sizes
CViewPropertySheet    m_PropSheet – the Property Sheet

CViewPropertySheet
BOOL Create(CWnd *pParentWnd, DWORD dwStyle, DWORD dwExStyle) – creates the
Property Sheet
void CenterControls(BOOL bCenter /* = TRUE */) – centers the controls on all
pages
virtual void AllowPageChange(BOOL bAllowPageChange = TRUE) – allow/disallow
changing to a different page

CViewPropertyPage
void EnableControls(BOOL bEnable) – enable/disable all controls on a page

CPropPgFormDoc
Nothing

In addition, the WM_NOTIFY TCN_SELCHANGE  page change notification message is
reflected to the derived CPropPgFormView window.

Please look at the provided project for a better understanding of the implementation
details.

Downloads

Download demo project – 39 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.