Auto Property Sheet in FormView

Saturday Dec 11th 1999 by Rick Shide
Share:

Classes that Enable the Use of Implement Property Sheets in Form Views

This article was contributed by Richard Shide.

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

History

Date Posted: December 11, 1999

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved