Using Tabbed Property Pages

HomeOverviewHow Do I

It’s recommended that your Windows 95 application use tabbed property pages where applicable. Tabbed property pages are useful for dialogs whose purpose is to let the user modify the attributes of some object on the screen. MFC provides support for property pages through the classes CPropertySheet and CPropertyPage.

The DRAWCLI sample previously used a dialog box to allow the user to set the fill mode and the pen size. For consistency with the Windows 95 user-interface guidelines, DRAWCLI now uses a property page to do so.

You can use the Gallery to add a property sheet to your application. However, for DRAWCLI, the task is not adding a property sheet, but converting an existing dialog into a property sheet. Depending on your application’s needs, you can use the Gallery to add property sheets and modify them as needed, or you can add them manually.

If you’re converting an existing dialog box to a property page, use the following procedure:

To display the property page, attach it to a CPropertySheet object and call DoModal on the CPropertySheet object. Here’s how DRAWCLI does it, in its implementation of CDrawObj::OnOpen:

CPropertySheet sheet( "Shape Properties" );
CRectDlg dlg; // derived from CPropertyPage

dlg.m_bNoFill = !m_bBrush;
dlg.m_penSize = m_bPen ? m_logpen.lopnWidth.x : 0;
sheet.AddPage( &dlg );

if (sheet.DoModal() != IDOK)
   return;

m_bBrush = !dlg.m_bNoFill;
m_bPen = dlg.m_penSize > 0;
if (m_bPen)
{
   m_logpen.lopnWidth.x = dlg.m_penSize;
   m_logpen.lopnWidth.y = dlg.m_penSize;
}

The string passed to the constructor for CPropertySheet is used as the title in the dialog’s title bar. Before calling DoModal, the current values are copied into the property sheet. After DoModal returns, the new values are copied back.

The following figure shows what DRAWCLI’s property page looks like. For more information on implementing property pages with MFC, see Property Sheets and Property Pages and the descriptions of CPropertyPage and CPropertySheet in the Class Library Reference. For a demonstration of different types of property sheets, see the PROPDLG sample application in the MFC samples.

DRAWCLI’s New Property Sheet