For the MFC-based sample, I decided to use the built-in classes CPropertySheet and CPropertyPage, which require considerably less code than I had to implement in the C version of the sample. The property sheet is displayed in response to the House Properties command.
void CMfcexpView::OnProperties ()
{
if (m_iSelected == -1)
return;
// Create a property sheet object.
CPropertySheet dlgPropertySheet ("House Properties",
this);
CHouse dlgHouse;
CAgent dlgAgent;
int index, count;
LV_ITEM lvItem;
char szAddSave [MAX_ADDRESS];
dlgPropertySheet.AddPage (&dlgHouse);
dlgPropertySheet.AddPage (&dlgAgent);
// Fill in the list box with the cities.
for (index = 0; index < m_NumCities; index++)
SendDlgItemMessage (IDC_CITY, CB_ADDSTRING, 0,
(LPARAM) (LPCTSTR) m_rgCities[index].szCity);
// Get the index to the selected list view item.
index = m_ListCtl.GetNextItem (-1, LVNI_SELECTED);
// Get the house address.
lvItem.iItem = index;
lvItem.iSubItem = 0;
lvItem.mask = LVIF_TEXT;
lvItem.cchTextMax = sizeof (szAddSave);
lvItem.pszText = szAddSave;
m_ListCtl.GetItem (&lvItem);
// Find the house in the list.
for (count = 0; count < m_NumHouses; count++)
{
if (strcmp (lvItem.pszText, m_rgHouses[count].szAddress) == 0)
break;
}
m_iSelHouse = count;
dlgHouse.m_Address = m_rgHouses[m_iSelHouse].szAddress;
dlgHouse.m_City = m_rgHouses[m_iSelHouse].szCity;
dlgHouse.m_Price = m_rgHouses[m_iSelHouse].iPrice;
dlgHouse.m_Bedrooms = m_rgHouses[m_iSelHouse].iBeds ;
dlgHouse.m_Bathrooms = m_rgHouses[m_iSelHouse].iBaths;
dlgAgent.m_AgentName = m_rgHouses[m_iSelHouse].szAgent;
dlgAgent.m_PhoneNumber = m_rgHouses[m_iSelHouse].szNumber;
if (dlgPropertySheet.DoModal () == IDOK)
{
m_rgHouses[m_iSelHouse].szAddress = dlgHouse.m_Address;
m_rgHouses[m_iSelHouse].szCity = dlgHouse.m_City;
m_rgHouses[m_iSelHouse].iPrice = dlgHouse.m_Price;
m_rgHouses[m_iSelHouse].iBeds = dlgHouse.m_Bedrooms;
m_rgHouses[m_iSelHouse].iBaths = dlgHouse.m_Bathrooms;
m_rgHouses[m_iSelHouse].szAgent = dlgAgent.m_AgentName;
m_rgHouses[m_iSelHouse].szNumber = dlgAgent.m_PhoneNumber;
GetDocument() -> SetModifiedFlag();
GetDocument() -> UpdateAllViews(NULL);
}
}