共用方式為


Property Sheets: Exchanging Data

OverviewHow Do I

As with most dialog boxes, the exchange of data between the property sheet and the application is one of the most important functions of the property sheet. This article describes how to accomplish this task.

Exchanging data with a property sheet is actually a matter of exchanging data with the individual property pages of the property sheet. The procedure for exchanging data with a property page is the same as for exchanging data with a dialog box, since a object is just a specialized object. The procedure takes advantage of the framework’s dialog data exchange (DDX) facility, which exchanges data between controls in a dialog box and member variables of the dialog box object.

The important difference between exchanging data with a property sheet and with a normal dialog box is that the property sheet has multiple pages, so you must exchange data with all the pages in the property sheet. For more information on DDX, see Dialog Data Exchange and Validation.

The following example illustrates exchanging data between a view and two pages of a property sheet:

void CMyView::DoModalPropertySheet()
{
   CPropertySheet propsheet;
   CMyFirstPage pageFirst; // derived from CPropertyPage
   CMySecondPage pageSecond; // derived from CPropertyPage

   // Move member data from the view (or from the currently
   // selected object in the view, for example).
   pageFirst.m_nMember1 = m_nMember1;
   pageFirst.m_nMember2 = m_nMember2;

   pageSecond.m_strMember3 = m_strMember3;
   pageSecond.m_strMember4 = m_strMember4;

   propsheet.AddPage(&pageFirst);
   propsheet.AddPage(&pageSecond);

   if (propsheeet.DoModal() == IDOK)
   {
      m_nMember1 = pageFirst.m_nMember1;
      m_nMember2 = pageFirst.m_nMember2;
      m_strMember3 = pageSecond.m_strMember3;
      m_strMember4 = pageSecond.m_strMember4; 
      GetDocument()->SetModifiedFlag();
      GetDocument()->UpdateAllViews(NULL);
   }
}

See Also   Property Sheets