pagea3.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 19k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <string.h>
  4. #include <prsht.h>
  5. #include <tchar.h>
  6. #include <shlwapi.h>
  7. #include <shlobj.h>
  8. #include <shellids.h>
  9. #include "winreg.h"
  10. #include "resource.h"
  11. #include "shwizard.h"
  12. #define DXA_GROWTH_CONST    10
  13. #define CUSTOMIZE_ALWAYS    TEXT('A')
  14. #define CUSTOMIZE_NEVER     TEXT('N')
  15. #define CUSTOMIZE_DEFAULT   TEXT('D')
  16. #define CUSTOMIZE_ONCHOICE  TEXT('O')
  17. #include <commctrl.h>   // The DSA functions are implemented here
  18. HDSA g_hdsaTemplateInfo = NULL;
  19. int g_nNextTemplateId = 0;
  20. const TCHAR c_szWebvwTemplatePreview[] = TEXT("WebvwTemplatePreview");
  21. HWND g_hwndLV_Templates = NULL;
  22. HWND g_hwndText_Desc = NULL;
  23. HWND g_hwndBitmap_Preview = NULL;
  24. HWND g_hwndDlg = NULL;
  25. TCHAR g_szTemplateFile[MAX_PATH];
  26. TCHAR g_szPreviewBitmapFile[MAX_PATH];
  27. TCHAR g_szKey[20];
  28. INT_PTR APIENTRY PageA3Proc (HWND, UINT, WPARAM, LPARAM);
  29. BOOL PageA3_OnInitDialog (HWND);
  30. void PageA3_OnSetActive  (HWND);
  31. void PageA3_OnWizardBack (HWND);
  32. void PageA3_OnWizardNext (HWND);
  33. void PageA3CleanUp();
  34. BOOL LoadWebViewTemplatesInfoFromRegistry();
  35. BOOL LoadTemplateInfo(HKEY hkey, LPCTSTR pszKey);
  36. BOOL AddInfoToTemplateList(WebViewTemplateInfo* pwvTemplate);
  37. BOOL InitTemplateListView(HWND hDlg);
  38. void FillTemplateListView(BOOL fEmpty);
  39. BOOL GetTemplateInfoByIndex(int iIndex, WebViewTemplateInfo* pwvTemplate);
  40. int AppendTemplateToListView(WebViewTemplateInfo* pwvTemplate);
  41. void SetDefaultSelection();
  42. void SetSelectionByIndex(int iIndex);
  43. int GetTemplateInfoById(int iId, WebViewTemplateInfo* pwvTemplate);
  44. void SetCheck_Customizable(LPCTSTR lpszCustomizable);
  45. void SetText_CustomizedPreview(LPCTSTR pszCustomizable, LPCTSTR pszPreviewBitmapFile);
  46. void SetTemplateDescription(LPCTSTR lpszDesc);
  47. void ShowPreviewBitmap(LPCTSTR pszPreviewBitmapFile);
  48. void TemplateLV_OnItemChanged();
  49. void PageA3OnDestroy();
  50. void EmptyTemplateList();
  51. // Not used currently
  52. #if 0
  53. void SetSelectionById(int iId);
  54. void EmptyTemplateListview();
  55. #endif
  56. INT_PTR APIENTRY PageA3Proc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  57. {
  58.     BOOL bRet = TRUE;
  59.     switch (msg)
  60.     {
  61.     case WM_COMMAND:
  62.         break;
  63.     case WM_INITDIALOG:
  64.         return PageA3_OnInitDialog(hDlg);
  65.     case WM_DESTROY:
  66.     {
  67.         PageA3OnDestroy();
  68.         if (g_pCommonInfo->WasItCustomized() && g_pCommonInfo->WasThisOptionalPathUsed(IDD_PAGEA3))
  69.         {
  70.             UpdateAddWebView(); // Update desktop.ini
  71.         }
  72.         else
  73.         {
  74.             PageA3CleanUp();
  75.         }
  76.         break;
  77.     }
  78.     case WM_NOTIFY:
  79.     {
  80.         switch (((NMHDR FAR *)lParam)->code)
  81.         {
  82.         case PSN_QUERYCANCEL:
  83.             bRet = FALSE;
  84.         case PSN_KILLACTIVE:
  85.         case PSN_RESET:
  86.             Unsubclass(GetDlgItem(hDlg, IDC_BITMAP_PREVIEW));
  87.             g_pCommonInfo->OnCancel(hDlg);
  88.             break;
  89.         case PSN_SETACTIVE:
  90.             Subclass(GetDlgItem(hDlg, IDC_BITMAP_PREVIEW));
  91.             PageA3_OnSetActive(hDlg);
  92.             // Make sure that the global webview is on.
  93.             if (ProdWebViewOn(hDlg))
  94.             {
  95.                 break;  // Continue with normal processing
  96.             }
  97.             // Fall through - i.e., if not g_fProceed, go back to the start page.
  98.         case PSN_WIZBACK:
  99.             Unsubclass(GetDlgItem(hDlg, IDC_BITMAP_PREVIEW));
  100.             PageA3_OnWizardBack(hDlg);
  101.             break;
  102.         case PSN_WIZNEXT:
  103.             Unsubclass(GetDlgItem(hDlg, IDC_BITMAP_PREVIEW));
  104.             PageA3_OnWizardNext(hDlg);
  105.             break;
  106.         case LVN_ITEMCHANGED:
  107.         {
  108.             NM_LISTVIEW* pnmlv = (NM_LISTVIEW*)lParam;
  109.             if ((pnmlv->uChanged & LVIF_STATE) &&
  110.                     (pnmlv->uNewState & LVIS_SELECTED))
  111.             {
  112.                 TemplateLV_OnItemChanged();
  113.             }
  114.         }
  115.         default:
  116.             bRet = FALSE;
  117.         }
  118.         break;
  119.     }
  120.     default:
  121.         bRet = FALSE;
  122.     }
  123.     return bRet;
  124. }
  125. BOOL PageA3_OnInitDialog (HWND hDlg)
  126. {
  127.     BOOL fRet = FALSE;
  128.     g_hwndDlg = hDlg;
  129.     if (LoadWebViewTemplatesInfoFromRegistry() && InitTemplateListView(hDlg))
  130.     {
  131.         g_hwndText_Desc = GetDlgItem(hDlg, IDC_TEXT_DESC);
  132.         g_hwndBitmap_Preview = GetDlgItem(hDlg, IDC_BITMAP_PREVIEW);
  133.         if (g_hwndText_Desc && g_hwndBitmap_Preview)
  134.         {
  135.             SetDefaultSelection();
  136.             fRet = TRUE;
  137.         }
  138.     }
  139.     return fRet;
  140. }   /*  end PageA3_OnInitDialog() */
  141. BOOL LoadWebViewTemplatesInfoFromRegistry()
  142. {
  143.     BOOL fRet = FALSE;
  144.     HKEY hkey;
  145.     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_WEBVIEW_TEMPLATES, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
  146.     {
  147.         WebViewTemplateInfo wvTemplate;
  148.         // If the folder was previously customized, add the Current template to the list.
  149.         int fPrevCustom = HasPersistMoniker(wvTemplate.szTemplateFile, ARRAYSIZE(wvTemplate.szTemplateFile),
  150.                 wvTemplate.szPreviewBitmapFile, ARRAYSIZE(wvTemplate.szPreviewBitmapFile));
  151.         if (fPrevCustom != PM_NONE)
  152.         {
  153.             wvTemplate.szKey[0] = TEXT('');
  154.             LoadString(g_hAppInst, IDS_CURRENT_TEMPLATE, wvTemplate.szFriendlyName, ARRAYSIZE(wvTemplate.szFriendlyName));
  155.             if (fPrevCustom == PM_LOCAL)
  156.             {
  157.                 wvTemplate.chCustomizable[0] = CUSTOMIZE_ALWAYS;
  158.             }
  159.             else
  160.             {
  161.                 wvTemplate.chCustomizable[0] = CUSTOMIZE_NEVER;
  162.             }
  163.             wvTemplate.chCustomizable[1] = TEXT('');
  164.             LoadString(g_hAppInst, IDS_CURRENT_TEMPLATE_DESC, wvTemplate.szDecsription, ARRAYSIZE(wvTemplate.szDecsription));
  165.             wvTemplate.iId = g_nNextTemplateId++;   // Used to identify the selected item in listview
  166.             if (AddInfoToTemplateList(&wvTemplate))
  167.             {
  168.                 fRet = TRUE;    // Return TRUE if we get even one template in the list.
  169.             }
  170.         }
  171.         TCHAR szKey[MAX_PATH];
  172.         // Read-in info of every template
  173.         for (int i = 0; RegEnumKey(hkey, i, szKey, ARRAYSIZE(szKey)) == ERROR_SUCCESS; i++)
  174.         {
  175.             // Return TRUE if even one template is read-in.
  176.             if (LoadTemplateInfo(hkey, szKey))
  177.             {
  178.                 fRet = TRUE;
  179.             }
  180.         }
  181.         RegCloseKey(hkey);
  182.     }
  183.     return fRet;
  184. }
  185. BOOL LoadTemplateInfo(HKEY hkey, LPCTSTR pszKey)
  186. {
  187.     BOOL fRet = FALSE;
  188.     HKEY hkeyTemplate;
  189.     if (RegOpenKeyEx(hkey, pszKey, 0, KEY_READ, &hkeyTemplate) == ERROR_SUCCESS)
  190.     {
  191.         DWORD cbSize, dwType;
  192.         WebViewTemplateInfo wvTemplate;
  193.         cbSize = sizeof(wvTemplate.szFriendlyName);
  194.         if ((RegQueryValueEx(hkeyTemplate, REG_VAL_DISPLAYNAME, NULL, &dwType, (LPBYTE)wvTemplate.szFriendlyName, &cbSize) == ERROR_SUCCESS)
  195.                 && wvTemplate.szFriendlyName[0])
  196.         {
  197.             // Save the key name
  198.             lstrcpyn(wvTemplate.szKey, pszKey, sizeof(wvTemplate.szKey));
  199.             // Read in the Read-only flag.
  200.             cbSize = sizeof(wvTemplate.chCustomizable);
  201.             if (RegQueryValueEx(hkeyTemplate, REG_VAL_CUSTOMIZABLE, NULL, &dwType, (LPBYTE)wvTemplate.chCustomizable, &cbSize) != ERROR_SUCCESS)
  202.             {
  203.                 wvTemplate.chCustomizable[0] = CUSTOMIZE_NEVER;
  204.                 wvTemplate.chCustomizable[1] = TEXT('');
  205.             }
  206.             // Read in the Template file name.
  207.             cbSize = sizeof(wvTemplate.szTemplateFile);
  208.             if (RegQueryValueEx(hkeyTemplate, REG_VAL_TEMPLATEFILE, NULL, &dwType, (LPBYTE)wvTemplate.szTemplateFile, &cbSize) != ERROR_SUCCESS)
  209.             {
  210.                 wvTemplate.szTemplateFile[0] = TEXT('');
  211.             }
  212.             // Read in the Preview bitmap file name.
  213.             cbSize = sizeof(wvTemplate.szPreviewBitmapFile);
  214.             if (RegQueryValueEx(hkeyTemplate, REG_VAL_PREVIEWBITMAPFILE, NULL, &dwType, (LPBYTE)wvTemplate.szPreviewBitmapFile, &cbSize) != ERROR_SUCCESS)
  215.             {
  216.                 wvTemplate.szPreviewBitmapFile[0] = TEXT('');
  217.             }
  218.             // Read in the template Decsription.
  219.             cbSize = sizeof(wvTemplate.szDecsription);
  220.             if (RegQueryValueEx(hkeyTemplate, REG_VAL_DESCRIPTION, NULL, &dwType, (LPBYTE)wvTemplate.szDecsription, &cbSize) != ERROR_SUCCESS)
  221.             {
  222.                 wvTemplate.szDecsription[0] = TEXT('');
  223.             }
  224.             wvTemplate.iId = g_nNextTemplateId++;   // Used to identify the selected item in listview
  225.             // Add this TemplateInfo to the TemplateInfo list.
  226.             fRet = AddInfoToTemplateList(&wvTemplate);
  227.         }
  228.         RegCloseKey(hkeyTemplate);
  229.     }
  230.     return fRet;
  231. }
  232. // Adds template info read-in from the registry into a DSA
  233. BOOL AddInfoToTemplateList(WebViewTemplateInfo* pwvTemplate)
  234. {
  235.     BOOL fRet = FALSE;
  236.     if (pwvTemplate)
  237.     {
  238.         if (g_hdsaTemplateInfo == NULL)
  239.         {
  240.             g_hdsaTemplateInfo = DSA_Create(sizeof(WebViewTemplateInfo), DXA_GROWTH_CONST);
  241.         }
  242.         if (g_hdsaTemplateInfo)
  243.         {
  244.             if (DSA_AppendItem(g_hdsaTemplateInfo, pwvTemplate) != -1)
  245.             {
  246.                 fRet = TRUE;
  247.             }
  248.         }
  249.     }
  250.     return fRet;
  251. }
  252. void PageA3OnDestroy()
  253. {
  254.     EmptyTemplateList();    // Free the list
  255. }
  256. BOOL InitTemplateListView(HWND hDlg)
  257. {
  258.     BOOL fRet = FALSE;
  259.     
  260.     g_hwndLV_Templates = GetDlgItem(hDlg, IDC_LIST_TEMPLATES);
  261.     if (g_hwndLV_Templates && g_hdsaTemplateInfo)
  262.     {
  263.         // Add the single column that we want.
  264.         LV_COLUMN lvc;
  265.         lvc.mask = LVCF_FMT | LVCF_SUBITEM;
  266.         lvc.fmt = LVCFMT_LEFT;
  267.         lvc.iSubItem = 0;
  268.         ListView_InsertColumn(g_hwndLV_Templates, 0, &lvc);
  269.         // Fill up the listview
  270.         FillTemplateListView(FALSE);
  271.         fRet = TRUE;
  272.     }
  273.     return fRet;
  274. }
  275. // Fill the listview with templates' friendly names. The parameter is not used currently.
  276. void FillTemplateListView(BOOL fEmpty)
  277. {
  278.     if (g_hdsaTemplateInfo) {
  279.         // Disable redraws while we mess repeatedly with the listview contents.
  280.         SendMessage(g_hwndLV_Templates, WM_SETREDRAW, FALSE, 0);
  281. // Not used currently
  282. #if 0
  283.         if (fEmpty)
  284.         {
  285.             EmptyTemplateListview();
  286.             EmptyTemplateList();
  287.         }
  288. #endif
  289.         // Add each template to the listview.
  290.         for (int nTemplate = 0; nTemplate < DSA_GetItemCount(g_hdsaTemplateInfo); nTemplate++)
  291.         {
  292.             // First, get the Template
  293.             WebViewTemplateInfo wvTemplate;
  294.             if (GetTemplateInfoByIndex(nTemplate, &wvTemplate))
  295.             {
  296.                 AppendTemplateToListView(&wvTemplate);
  297.             }
  298.         }
  299.         // Reenable redraws.
  300.         SendMessage(g_hwndLV_Templates, WM_SETREDRAW, TRUE, 0);
  301.         InvalidateRect(g_hwndLV_Templates, NULL, TRUE);
  302.     }
  303. }
  304. // Not used currently. Could be used if we have a Reset All or Delete All option.
  305. #if 0
  306. void EmptyTemplateListview()
  307. {
  308.     if (g_hdsaTemplateInfo) {
  309.         SendMessage(g_hwndLV_Templates, WM_SETREDRAW, FALSE, 0);
  310.         int cTemplate = DSA_GetItemCount(g_hdsaTemplateInfo);
  311.         for (int nTemplate = 0; nTemplate < cTemplate; nTemplate++)
  312.         {
  313.             ListView_DeleteItem(g_hwndLV_Templates, 0);
  314.         }
  315.         SendMessage(g_hwndLV_Templates, WM_SETREDRAW, TRUE, 0);
  316.         InvalidateRect(g_hwndLV_Templates, NULL, TRUE);
  317.     }
  318. }
  319. #endif
  320. // Frees each item of the template list. It finally destroys the list as well.
  321. void EmptyTemplateList()
  322. {
  323.     if (g_hdsaTemplateInfo)
  324.     {
  325.         // DSA_Destroy will implicitly delete the items too
  326.         DSA_Destroy(g_hdsaTemplateInfo);
  327.         g_hdsaTemplateInfo = NULL;
  328.     }
  329. }
  330. // Given a listview (which should be in sync with the DSA list) index, it returns the template info
  331. BOOL GetTemplateInfoByIndex(int iIndex, WebViewTemplateInfo* pwvTemplate)
  332. {
  333.     BOOL fRet = FALSE;
  334.     if (g_hdsaTemplateInfo)
  335.     {
  336.         if (DSA_GetItem(g_hdsaTemplateInfo, iIndex, pwvTemplate) != -1)
  337.         {
  338.             fRet = TRUE;
  339.         }
  340.     }
  341.     return fRet;
  342. }
  343. // Appends a new template's FriendlyName to the end of the listview
  344. int AppendTemplateToListView(WebViewTemplateInfo* pwvTemplate)
  345. {
  346.     // Construct the listview item.
  347.     LV_ITEM lvi = {0};
  348.     lvi.mask = LVIF_TEXT | LVIF_PARAM;
  349.     lvi.iItem = 0x7FFFFFFF; // Insert at the end.
  350.     lvi.pszText = pwvTemplate->szFriendlyName;
  351.     lvi.lParam = pwvTemplate->iId;
  352.     int iIndex = ListView_InsertItem(g_hwndLV_Templates, &lvi);
  353.     if (iIndex != -1)
  354.     {
  355.         ListView_SetColumnWidth(g_hwndLV_Templates, 0, LVSCW_AUTOSIZE);
  356.     }
  357.     return iIndex;
  358. }
  359. // Currently, the 0'th is chosen as the default
  360. void SetDefaultSelection()
  361. {
  362.     if (g_hdsaTemplateInfo && DSA_GetItemCount(g_hdsaTemplateInfo))
  363.     {
  364.         SetSelectionByIndex(0); // By default, select the '0'th item.
  365.     }
  366.     EnableWindow(g_hwndLV_Templates, TRUE);
  367. }
  368. // Sets the selection in the listview, given an index
  369. void SetSelectionByIndex(int iIndex)
  370. {
  371.     if (iIndex >= 0 && g_hdsaTemplateInfo && iIndex < DSA_GetItemCount(g_hdsaTemplateInfo))
  372.     {
  373.         // Set the focus on the 'iIndex'th item
  374.         ListView_SetItemState(g_hwndLV_Templates, iIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  375.         // Get the 'iIndex'th item
  376.         LV_ITEM lvi = {0};
  377.         lvi.mask = LVIF_PARAM;
  378.         lvi.iItem = iIndex;
  379.         ListView_GetItem(g_hwndLV_Templates, &lvi);
  380.         WebViewTemplateInfo wvTemplate;
  381.         GetTemplateInfoById((int)lvi.lParam, &wvTemplate);
  382.         // Set the customize checkbox.
  383.         SetCheck_Customizable(wvTemplate.chCustomizable);
  384.         // Show/Hide the customized preview text.
  385.         SetText_CustomizedPreview(wvTemplate.chCustomizable, wvTemplate.szPreviewBitmapFile);
  386.         // Set the description.
  387.         SetTemplateDescription(wvTemplate.szDecsription);
  388.         // Show the Preview bitmap.
  389.         ShowPreviewBitmap(wvTemplate.szPreviewBitmapFile);
  390.     }
  391. }
  392. // Given a template's id, it returns other info by searching for it in the template list
  393. int GetTemplateInfoById(int iId, WebViewTemplateInfo* pwvTemplate)
  394. {
  395.     int iIndex = -1;
  396.     WebViewTemplateInfo wvTemplate;
  397.     if (g_hdsaTemplateInfo) {
  398.         // For each template
  399.         for (int nTemplate = 0; nTemplate < DSA_GetItemCount(g_hdsaTemplateInfo)
  400.                 && GetTemplateInfoByIndex(nTemplate, &wvTemplate); nTemplate++)
  401.         {
  402.             // If the Id's match
  403.             if (wvTemplate.iId == iId)
  404.             {
  405.                 *pwvTemplate = wvTemplate;
  406.                 iIndex = nTemplate;
  407.                 break;
  408.             }
  409.         }
  410.     }
  411.     return iIndex;
  412. }
  413. // Not used currently. Given a template id, this func. sets it to be selected in the listview
  414. #if 0
  415. void SetSelectionById(int iId)
  416. {
  417.     WebViewTemplateInfo wvTemplate;
  418.     int iIndex = GetTemplateInfoById(iId, &wvTemplate);
  419.     if (iIndex > 0)
  420.     {
  421.         SetSelectionByIndex(iIndex);
  422.     }
  423. }
  424. #endif
  425. #define toupper(c) ((TCHAR)CharUpper((LPTSTR)c))
  426. // Sets the text that specifies whether the template is customizable or not
  427. void SetCheck_Customizable(LPCTSTR lpszCustomizable)
  428. {
  429.     // Check/Uncheck it
  430.     if (toupper(lpszCustomizable[0]) == CUSTOMIZE_ALWAYS || toupper(lpszCustomizable[0]) == CUSTOMIZE_DEFAULT)
  431.     {
  432.         CheckDlgButton(g_hwndDlg, IDC_CHECK1, BST_CHECKED);
  433.     }
  434.     else
  435.     {
  436.         CheckDlgButton(g_hwndDlg, IDC_CHECK1, BST_UNCHECKED);
  437.     }
  438.     // Enable/Disable it
  439.     if (toupper(lpszCustomizable[0]) == CUSTOMIZE_ALWAYS || toupper(lpszCustomizable[0]) == CUSTOMIZE_NEVER)
  440.     {
  441.         EnableWindow(GetDlgItem(g_hwndDlg, IDC_CHECK1), FALSE);
  442.     }
  443.     else
  444.     {
  445.         EnableWindow(GetDlgItem(g_hwndDlg, IDC_CHECK1), TRUE);
  446.     }
  447. }
  448. // Show the customized preview text for the "Current" template. Hide it otherwise.
  449. void SetText_CustomizedPreview(LPCTSTR pszCustomizable, LPCTSTR pszPreviewBitmapFile)
  450. {
  451.     TCHAR szText[MAX_PATH];
  452.     szText[0] = TEXT('');
  453.     if (!pszPreviewBitmapFile || !pszPreviewBitmapFile[0])
  454.     {
  455.         LoadString(g_hAppInst, IDS_NOTAVAILABLE, szText, ARRAYSIZE(szText));
  456.     }
  457.     else if (pszCustomizable[0] == CUSTOMIZE_ALWAYS)
  458.     {
  459.         LoadString(g_hAppInst, IDS_ORIGINAL, szText, ARRAYSIZE(szText));
  460.     }
  461.     else
  462.     {
  463.         LoadString(g_hAppInst, IDS_PREVIEW, szText, ARRAYSIZE(szText));
  464.     }
  465.     SendMessage(GetDlgItem(g_hwndDlg, IDC_TEXT_CUSTOMIZED), WM_SETTEXT, 0, (LPARAM)szText);
  466. }
  467. // Sets the given desc. text in the desc. dialog item
  468. void SetTemplateDescription(LPCTSTR lpszDesc)
  469. {
  470.     SendMessage(g_hwndText_Desc, WM_SETTEXT, 0, (LPARAM)lpszDesc);
  471. }
  472. // Makes the given bmp file be shown in the preview dialog item
  473. void ShowPreviewBitmap(LPCTSTR pszPreviewBitmapFile)
  474. {
  475.     if (pszPreviewBitmapFile && pszPreviewBitmapFile[0])
  476.     {
  477.         DisplayPreview(pszPreviewBitmapFile, g_hwndBitmap_Preview);
  478.     }
  479.     else
  480.     {
  481.         DisplayUnknown(g_hwndBitmap_Preview);
  482.     }
  483. }
  484. // Changes all the appropriate dialog items
  485. void TemplateLV_OnItemChanged()
  486. {
  487.     int iIndex = ListView_GetNextItem(g_hwndLV_Templates, -1, LVNI_SELECTED);
  488.     SetSelectionByIndex(iIndex);
  489. }
  490. // Sets the appropriate wizard buttons
  491. void PageA3_OnSetActive (HWND hDlg)
  492. {
  493.     g_pCommonInfo->OnSetActive(hDlg);
  494.     // Make the preview etc. match the selection
  495.     TemplateLV_OnItemChanged();
  496. }   /*  end PageA3_OnSetActive() */
  497. void PageA3CleanUp()
  498. {
  499.     // Remove desktop.ini only if we had copied it during this wizard session
  500.     if (g_bTemplateCopied)
  501.     {
  502.         DeleteFile(g_szFullHTMLFile);
  503.         g_bTemplateCopied = FALSE;
  504.     }
  505. }
  506. void PageA3_OnWizardBack(HWND hDlg)
  507. {
  508.     PageA3CleanUp();
  509.     g_pCommonInfo->OnBack(hDlg);
  510. }
  511. // Launches the template in an editor, if it is editable
  512. void PageA3_OnWizardNext (HWND hDlg)
  513. {
  514.     WebViewTemplateInfo wvTemplate;
  515.     int iIndex = ListView_GetNextItem(g_hwndLV_Templates, -1, LVNI_SELECTED);
  516.     if (GetTemplateInfoByIndex(iIndex, &wvTemplate))
  517.     {
  518.         lstrcpy(g_szTemplateFile, wvTemplate.szTemplateFile);
  519.         // Copy the reg key name
  520.         lstrcpyn(g_szKey, wvTemplate.szKey, ARRAYSIZE(g_szKey));
  521.         
  522.         // Copy the PreviewBitmapFile name into g_szPreviewBitmapFile
  523.         lstrcpy(g_szPreviewBitmapFile, wvTemplate.szPreviewBitmapFile);
  524.         TCHAR szKeyVersion[MAX_PATH];
  525.         GetWebViewTemplateKeyVersion(wvTemplate.szKey, szKeyVersion, ARRAYSIZE(szKeyVersion));
  526.         
  527.         if ((wvTemplate.chCustomizable[0] == CUSTOMIZE_NEVER)
  528.                 || ((szKeyVersion[0] && (StrCmpI(szKeyVersion, TEXT("IE4")) != 0))    // Only for non-IE4 templates
  529.                 && (wvTemplate.chCustomizable[0] == CUSTOMIZE_ONCHOICE)
  530.                 && !IsDlgButtonChecked(g_hwndDlg, IDC_CHECK1)))     // No local copy if we are not changing the template
  531.         {
  532.             //Do not launch HTML editor.
  533.             g_iFlagA = SYSTEM_TEMPLATE;
  534.         }
  535.         else
  536.         {
  537.             g_iFlagA = CUSTOM_TEMPLATE;
  538.             CopyTemplate();
  539.         }
  540.         if (IsDlgButtonChecked(g_hwndDlg, IDC_CHECK1)) // The selected item is a custom template.
  541.         {
  542.             //Launch HTML editor.
  543.             LaunchRegisteredEditor();
  544.         }
  545.     }
  546.     else
  547.     {
  548.         g_iFlagA = NO_TEMPLATE;
  549.         g_szTemplateFile[0] = TEXT('');
  550.     }
  551.     
  552.     g_pCommonInfo->OnNext(hDlg);
  553. }