In this application, I implemented a property sheet with two property sheet pages. One allows the user to view and change the properties for a particular house listing (for example, the address and the city); the other displays information about the listing agent (for example, the agent's name and phone number), which the user can also change. Figure 7-4 shows the House Listing property sheet page.
Figure 7-4.
Processing a property sheet page is similar to processing a dialog box, with one major difference: when you process a property sheet page, you handle notifications instead of the commands generated for the OK and Cancel buttons. I could process my property sheet pages as follows:
To initialize the property sheet pages, I had to determine which house was currently selected and save that information for future reference. The House Listing page is displayed first. Responding to the WM_INITDIALOG message offers the first chance to determine the currently selected house. I used the code on the following page to determine the index of the selected house within my global array of houses.
char szTemp [MAX_ADDRESS];
static char szAddSave [MAX_ADDRESS];
static char szCitySave [MAX_CITY];
static int iPrice, iBeds, iBaths;
BOOL bErr;
int index, count;
LV_ITEM lvItem;
§
case WM_INITDIALOG:
// Fill in the list box with the cities.
for (index = 0; index < g_Listing.NumCities; index++)
SendDlgItemMessage (hDlg, IDE_CITY, CB_INSERTSTRING,
(WPARAM)(-1), (LPARAM)(rgCities[index].szCity));
// Get the index to the selected list view item.
index = ListView_GetNextItem (g_Listing.hWndListView,
-1, MAKELPARAM (LVNI_SELECTED, 0));
// Get the house address.
lvItem.iItem = index;
lvItem.iSubItem = 0;
lvItem.mask = LVIF_TEXT;
lvItem.cchTextMax = sizeof (szAddSave);
lvItem.pszText = szAddSave;
ListView_GetItem (g_Listing.hWndListView,&lvItem);
// Find the house in the list.
for (count = 0; count < g_Listing.NumHouses; count++)
{
if (strcmp (lvItem.pszText, rgHouses[count].szAddress) == 0)
break;
}
g_Listing.iSelHouse = count;
§
My other property sheet page, Listing Agent, allows the user to view and change the name and phone number of the listing agent associated with the selected house. I used similar code to handle this page, except that I modified the szAgent and szNumber members of the HOUSEINFO structure instead of altering the other house-specific fields. Figure 7-5 shows the Listing Agent property sheet page.
Figure 7-5.