+ PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
+ PropPageInfo * ppi, * prev_ppi = psInfo->proppage;
+ HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
+ LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
+ TCITEMW item;
+ int index;
+
+ TRACE("hwndDlg %p, hpageInsertAfter %p, hpage %p\n", hwndDlg, hpageInsertAfter, hpage);
+
+ if (IS_INTRESOURCE(hpageInsertAfter))
+ index = LOWORD(hpageInsertAfter);
+ else
+ {
+ index = PROPSHEET_GetPageIndex(hpageInsertAfter, psInfo, -1);
+ if (index < 0)
+ {
+ TRACE("Could not find page to insert after!\n");
+ return FALSE;
+ }
+ index++;
+ }
+
+ if (index > psInfo->nPages)
+ index = psInfo->nPages;
+
+ /*
+ * Allocate a new PropPageInfo entry.
+ */
+ ppi = Alloc(sizeof(PropPageInfo) * (psInfo->nPages + 1));
+ if (!ppi)
+ return FALSE;
+
+ /*
+ * Fill in a new PropPageInfo entry.
+ */
+ if (index > 0)
+ memcpy(ppi, prev_ppi, index * sizeof(PropPageInfo));
+ memset(&ppi[index], 0, sizeof(PropPageInfo));
+ if (index < psInfo->nPages)
+ memcpy(&ppi[index + 1], &prev_ppi[index], (psInfo->nPages - index) * sizeof(PropPageInfo));
+ psInfo->proppage = ppi;
+
+ if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, index, FALSE))
+ {
+ psInfo->proppage = prev_ppi;
+ Free(ppi);
+ return FALSE;
+ }
+
+ psInfo->proppage[index].hpage = hpage;
+
+ if (ppsp->dwFlags & PSP_PREMATURE)
+ {
+ /* Create the page but don't show it */
+ if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppsp))
+ {
+ psInfo->proppage = prev_ppi;
+ Free(ppi);
+ return FALSE;
+ }
+ }
+
+ Free(prev_ppi);
+ psInfo->nPages++;
+ if (index <= psInfo->active_page)
+ psInfo->active_page++;
+
+ /*
+ * Add a new tab to the tab control.
+ */
+ item.mask = TCIF_TEXT;
+ item.pszText = (LPWSTR) psInfo->proppage[index].pszText;
+ item.cchTextMax = MAX_TABTEXT_LENGTH;
+
+ if (psInfo->hImageList)
+ {
+ SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
+ }
+
+ if (psInfo->proppage[index].hasIcon)
+ {
+ item.mask |= TCIF_IMAGE;
+ item.iImage = index;
+ }
+
+ SendMessageW(hwndTabControl, TCM_INSERTITEMW, index,
+ (LPARAM)&item);
+
+ /* If it is the only page - show it */
+ if (psInfo->nPages == 1)
+ PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
+
+ return TRUE;