Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

770 lines
20 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // WIZARD.CPP / Tuneup
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1998
  7. // All rights reserved
  8. //
  9. // Wizard creation and common functions.
  10. //
  11. // 7/98 - Jason Cohen (JCOHEN)
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. //
  15. // Include file(s).
  16. //
  17. #include "main.h"
  18. #include <windowsx.h>
  19. #include <commctrl.h>
  20. #include <prsht.h>
  21. #include "startup.h"
  22. #include "schedwiz.h"
  23. #include "tasks.h"
  24. #include "timeschm.h"
  25. #include "cleanup.h"
  26. #include "summary.h"
  27. #include "runnow.h"
  28. //
  29. // Internal structure(s).
  30. //
  31. typedef struct _WIZPAGE
  32. {
  33. INT iDialog;
  34. LPTSTR lpTitle;
  35. LPTSTR lpSubTitle;
  36. struct _WIZPAGE * lpNext;
  37. } WIZPAGE, *PWIZPAGE, *LPWIZPAGE;
  38. //
  39. // Inernal function prototype(s).
  40. //
  41. // Wizard proc.
  42. //
  43. static INT_PTR APIENTRY WizardPageProc(HWND, UINT, WPARAM, LPARAM);
  44. // Message proccessing functions.
  45. //
  46. static BOOL OnInit(HWND, INT);
  47. static VOID OnDestroy(HWND, INT);
  48. static VOID OnCommand(HWND, INT, HWND, UINT);
  49. static BOOL OnNotify(HWND, INT, INT);
  50. static BOOL OnDrawItem(HWND, const DRAWITEMSTRUCT *);
  51. // Other common wizard functions.
  52. //
  53. static VOID InitBoldFont(HWND);
  54. static VOID FreeWizPages(LPWIZPAGE);
  55. static LPWIZPAGE CreateWizPage(LPWIZPAGE, INT, LPTSTR, LPTSTR);
  56. INT CreateWizard(HINSTANCE hInstance, HWND hWndParent)
  57. {
  58. LPPROPSHEETPAGE lppsPage;
  59. PROPSHEETHEADER psHeader;
  60. DWORD dwPages = 0;
  61. INT iReturn;
  62. LPWIZPAGE lpWizPageHead,
  63. lpWizPageBuffer;
  64. LPTASKDATA lpTasks;
  65. // Make sure the common constrols are loaded and ready to use.
  66. //
  67. InitCommonControls();
  68. // Set the current job pointer to the begining of
  69. // or global list of jobs.
  70. //
  71. g_CurrentTask = g_Tasks;
  72. // We always have the welcome dialog in the wizard.
  73. // If the first memory allocation fails, we have to bail.
  74. //
  75. if ( lpWizPageHead = (LPWIZPAGE) MALLOC(sizeof(WIZPAGE)) )
  76. {
  77. lpWizPageBuffer = lpWizPageHead;
  78. lpWizPageBuffer->iDialog = IDD_WELCOME;
  79. }
  80. else
  81. return -1;
  82. // Add the time page.
  83. //
  84. lpWizPageBuffer = CreateWizPage(lpWizPageBuffer, IDD_TIME, MAKEINTRESOURCE(IDS_TITLE_TIME), MAKEINTRESOURCE(IDS_SUBTITLE_TIME));
  85. // Add the startup group page.
  86. //
  87. if ( IsUserAdmin() || UserHasStartupItems() )
  88. lpWizPageBuffer = CreateWizPage(lpWizPageBuffer, IDD_STARTMENU, MAKEINTRESOURCE(IDS_TITLE_STARTMENU), MAKEINTRESOURCE(IDS_SUBTITLE_STARTMENU));
  89. // Create all the task pages.
  90. //
  91. for (lpTasks = g_Tasks; lpTasks; lpTasks = lpTasks->lpNext)
  92. lpWizPageBuffer = CreateWizPage(lpWizPageBuffer, lpTasks->nPageID, lpTasks->lpTitle, lpTasks->lpSubTitle);
  93. // Add the backup group page.
  94. //
  95. //lpWizPageBuffer = CreateWizPage(lpWizPageBuffer, IDD_BACKUP, MAKEINTRESOURCE(IDS_TITLE_BACKUP), MAKEINTRESOURCE(IDS_SUBTITLE_BACKUP));
  96. // We always have the summary page.
  97. // If this memory allocation fails, we must
  98. // free the others and bail out.
  99. //
  100. if ( lpWizPageBuffer->lpNext = (LPWIZPAGE) MALLOC(sizeof(WIZPAGE)) )
  101. {
  102. lpWizPageBuffer = lpWizPageBuffer->lpNext;
  103. lpWizPageBuffer->iDialog = IDD_SUMMARY;
  104. lpWizPageBuffer->lpNext = NULL;
  105. }
  106. else
  107. {
  108. lpWizPageBuffer->lpNext = NULL;
  109. FreeWizPages(lpWizPageHead);
  110. return -1;
  111. }
  112. // Get the number of pages.
  113. //
  114. for (lpWizPageBuffer = lpWizPageHead; lpWizPageBuffer; lpWizPageBuffer = lpWizPageBuffer->lpNext)
  115. dwPages++;
  116. // Alocate all the memory needed for all the wizard pages.
  117. //
  118. if ( (psHeader.ppsp = (LPCPROPSHEETPAGE) MALLOC(dwPages * sizeof(PROPSHEETPAGE))) == NULL )
  119. {
  120. FreeWizPages(lpWizPageHead);
  121. return -1;
  122. }
  123. // Setup the property sheet header.
  124. //
  125. psHeader.dwSize = sizeof(PROPSHEETHEADER);
  126. psHeader.hwndParent = hWndParent;
  127. psHeader.nPages = dwPages;
  128. psHeader.nStartPage = 0;
  129. psHeader.hInstance = hInstance;
  130. psHeader.pszIcon = MAKEINTRESOURCE(IDI_TUNEUP);
  131. #ifdef OLDWIZ
  132. psHeader.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE | PSH_WIZARD;
  133. #else
  134. // Wizard 97 only info.
  135. //
  136. psHeader.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE | PSH_WIZARD97 | PSH_HEADER | PSH_WATERMARK;
  137. psHeader.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
  138. psHeader.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
  139. #endif
  140. // Setup all the page sheet structures.
  141. //
  142. for ( lppsPage = (LPPROPSHEETPAGE) psHeader.ppsp, lpWizPageBuffer = lpWizPageHead;
  143. lppsPage - psHeader.ppsp < (INT) dwPages && lpWizPageBuffer;
  144. lppsPage++, lpWizPageBuffer = lpWizPageBuffer->lpNext)
  145. {
  146. // Assign all the values for this property sheet.
  147. //
  148. lppsPage->dwSize = sizeof(PROPSHEETPAGE);
  149. lppsPage->hInstance = hInstance;
  150. lppsPage->pszTemplate = MAKEINTRESOURCE(lpWizPageBuffer->iDialog);
  151. lppsPage->pfnDlgProc = WizardPageProc;
  152. lppsPage->pszTitle = MAKEINTRESOURCE(IDS_TUNEUP);
  153. lppsPage->lParam = lpWizPageBuffer->iDialog;
  154. #ifndef OLDWIZ
  155. // Wizard 97 only info.
  156. //
  157. switch (lpWizPageBuffer->iDialog)
  158. {
  159. case IDD_WELCOME:
  160. case IDD_SUMMARY:
  161. lppsPage->dwFlags = PSP_USETITLE | PSP_HIDEHEADER;
  162. break;
  163. default:
  164. lppsPage->dwFlags = PSP_USETITLE | PSP_USEHEADERSUBTITLE | PSP_USEHEADERTITLE;
  165. lppsPage->pszHeaderTitle = lpWizPageBuffer->lpTitle;
  166. lppsPage->pszHeaderSubTitle = lpWizPageBuffer->lpSubTitle;
  167. }
  168. #endif
  169. }
  170. // Create the wizard and save the return code.
  171. //
  172. iReturn = (INT)PropertySheet(&psHeader);
  173. // Free the memory for the property sheet wizard pages.
  174. //
  175. FREE(psHeader.ppsp);
  176. FreeWizPages(lpWizPageHead);
  177. // Return positive value if successfull.
  178. //
  179. return(iReturn);
  180. }
  181. static INT_PTR APIENTRY WizardPageProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  182. {
  183. // LPPROPSHEETPAGE lpsp;
  184. // PAINTSTRUCT ps;
  185. switch (message)
  186. {
  187. // Message cracking macros.
  188. //
  189. HANDLE_MSG(hDlg, WM_COMMAND, OnCommand);
  190. // Other messages to handle.
  191. //
  192. case WM_INITDIALOG:
  193. return OnInit(hDlg, (INT) (((LPPROPSHEETPAGE) lParam)->lParam));
  194. case WM_NOTIFY:
  195. return OnNotify(hDlg, (INT) GetWindowLongPtr(hDlg, DWLP_USER), ((NMHDR *) lParam)->code);
  196. case WM_DRAWITEM:
  197. return OnDrawItem(hDlg, (const DRAWITEMSTRUCT *) lParam);
  198. case WM_DESTROY:
  199. OnDestroy(hDlg, (INT) GetWindowLongPtr(hDlg, DWLP_USER));
  200. return FALSE;
  201. case WM_VKEYTOITEM:
  202. switch ( LOWORD(wParam) )
  203. {
  204. case _T(' '):
  205. StartupSelectItem(GetDlgItem(hDlg, IDC_STARTUP));
  206. return -2;
  207. default:
  208. return -1;
  209. }
  210. break;
  211. /*
  212. if ( g_hBoldFont && GetDlgItem(hDlg, IDC_HIGHTEXT) )
  213. SendDlgItemMessage(hDlg, IDC_HIGHTEXT, WM_SETFONT, (WPARAM) g_hBoldFont, MAKELPARAM(TRUE, 0));
  214. InitWizardPage(hDlg, lpsp->lParam);
  215. if (g_hStdPal == NULL) // We don't need to handle the bitmap in this environment.
  216. SendDlgItemMessage(hDlg, IDB_WIZBMP, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) (HANDLE) BmpData.hDib);
  217. break;
  218. case WM_DRAWITEM:
  219. PaintLine((DRAWITEMSTRUCT *) lParam);
  220. break;
  221. case WM_MEASUREITEM:
  222. OnMeasureItem((MEASUREITEMSTRUCT *) lParam, hDlg);
  223. break;
  224. case WM_PAINT:
  225. if (g_hStdPal)
  226. {
  227. BeginPaint(hDlg, &ps);
  228. PaintBitmap(&ps);
  229. EndPaint(hDlg, &ps);
  230. }
  231. else
  232. DefWindowProc(hDlg, message, wParam, lParam);
  233. break;
  234. case WM_ACTIVATE:
  235. if (g_hStdPal)
  236. InvalidateRect(hDlg, &BmpData.rect, FALSE);
  237. break;
  238. case WM_PALETTECHANGED:
  239. WmPaletteChanged(hDlg, wParam);
  240. break;
  241. case WM_QUERYNEWPALETTE:
  242. return WmQueryNewPalette(hDlg);
  243. */
  244. default:
  245. return FALSE;
  246. }
  247. return TRUE;
  248. }
  249. static BOOL OnInit(HWND hDlg, INT nPageId)
  250. {
  251. BOOL bTaskInit = FALSE;
  252. // Store page dialog resource in the window data for later.
  253. // That way we can tell what page we are on when we get a
  254. // notification message.
  255. //
  256. SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM) nPageId);
  257. // Now init the individule pages.
  258. //
  259. switch (nPageId)
  260. {
  261. case IDD_WELCOME:
  262. InitBoldFont(GetDlgItem(hDlg, IDC_STATIC_TITLE));
  263. CheckRadioButton(hDlg, IDC_EXPRESS, IDC_MANUAL, (g_dwFlags & TUNEUP_CUSTOM) ? IDC_MANUAL : IDC_EXPRESS);
  264. CenterWindow(GetParent(hDlg), NULL);
  265. break;
  266. case IDD_TIME:
  267. break;
  268. case IDD_STARTMENU:
  269. InitStartupMenu(hDlg);
  270. break;
  271. case IDD_CLEANUP:
  272. // Init the list box with the disk cleanup settings.
  273. //
  274. GetCleanupSettings(GetDlgItem(hDlg, IDC_LISTSET));
  275. bTaskInit = TRUE;
  276. break;
  277. case IDD_TASK:
  278. bTaskInit = TRUE;
  279. InitGenericTask(hDlg);
  280. break;
  281. case IDD_SUMMARY:
  282. InitBoldFont(GetDlgItem(hDlg, IDC_STATIC_TITLE));
  283. break;
  284. }
  285. // Do task init now.
  286. //
  287. if (bTaskInit)
  288. {
  289. if ( g_CurrentTask->dwOptions & TASK_SCHEDULED )
  290. CheckRadioButton(hDlg, IDC_YES, IDC_DENY, IDC_YES);
  291. else
  292. {
  293. CheckRadioButton(hDlg, IDC_YES, IDC_DENY, IDC_DENY);
  294. EnableWindow(GetDlgItem(hDlg, IDC_RESCHED), FALSE);
  295. EnableWindow(GetDlgItem(hDlg, IDC_SETTING), FALSE);
  296. EnableWindow(GetDlgItem(hDlg, IDC_SCHEDTEXT), FALSE);
  297. }
  298. SetDlgItemText(hDlg, IDC_TASKDESC, g_CurrentTask->lpDescription);
  299. }
  300. return FALSE;
  301. }
  302. //////////////////////////////////////////////////////////////////////////////
  303. //
  304. // INTERNAL:
  305. // OnDestroy()
  306. // - This function is called for every wizard dialog page when
  307. // the wizard is terminated either by finishing or canceling.
  308. // This should be used to free up any resources associated with
  309. // any of the wizard pages.
  310. //
  311. // ENTRY:
  312. // hDlg - Window handle to the wizard dialog being destroyed.
  313. // nPageId - Dialog resource ID for the dialog being destroyed.
  314. //
  315. // EXIT:
  316. // VOID
  317. //
  318. //////////////////////////////////////////////////////////////////////////////
  319. static VOID OnDestroy(HWND hDlg, INT nPageId)
  320. {
  321. switch (nPageId)
  322. {
  323. case IDD_WELCOME:
  324. case IDD_SUMMARY:
  325. // Release the font we created for the welcome and summary pages.
  326. //
  327. InitBoldFont(NULL);
  328. break;
  329. case IDD_STARTMENU:
  330. // Need to release the data associated with the items in the combo box.
  331. //
  332. ReleaseStartupMenu(hDlg);
  333. break;
  334. }
  335. }
  336. static VOID OnCommand(HWND hDlg, INT id, HWND hwndCtl, UINT codeNotify)
  337. {
  338. LPTSTR lpBuffer;
  339. switch (id)
  340. {
  341. // Welcome page:
  342. //
  343. case IDC_EXPRESS:
  344. g_dwFlags &= ~TUNEUP_CUSTOM;
  345. break;
  346. case IDC_MANUAL:
  347. g_dwFlags |= TUNEUP_CUSTOM;
  348. break;
  349. // Time page:
  350. //
  351. case IDC_CURRENT:
  352. case IDC_RESET:
  353. EnableWindow(GetDlgItem(hDlg, IDC_NIGHT), (id == IDC_RESET));
  354. EnableWindow(GetDlgItem(hDlg, IDC_DAY), (id == IDC_RESET));
  355. EnableWindow(GetDlgItem(hDlg, IDC_EVENING), (id == IDC_RESET));
  356. break;
  357. // Startup start menu group page:
  358. //
  359. #if 0 // No advanced button anymore.
  360. case IDC_ADVANCED:
  361. // Get the profiles directory and Shell Execute it.
  362. //
  363. if ( ( (lpBuffer = RegGetString(HKLM, g_szRegKeyProfiles, g_szRegValProfileDir)) == NULL ) ||
  364. ( (DWORD) ShellExecute(hDlg, _T("explore"), lpBuffer, NULL, NULL, SW_SHOWNORMAL) <= 32 ) )
  365. {
  366. // Error showing the folder.
  367. //
  368. // TODO:
  369. }
  370. // Free the buffer returned by RegGetString.
  371. // Macro automatically checks for NULL case before freeing.
  372. //
  373. FREE(lpBuffer);
  374. break;
  375. #endif
  376. case IDC_USERS:
  377. switch (codeNotify)
  378. {
  379. case CBN_SELCHANGE:
  380. InitStartupList(hDlg);
  381. break;
  382. }
  383. break;
  384. case IDC_STARTUP:
  385. if ( codeNotify == LBN_DBLCLK )
  386. StartupSelectItem(hwndCtl);
  387. break;
  388. // Disk space cleanup page:
  389. //
  390. case IDC_CUSETTING:
  391. ExecAndWait(GetParent(hDlg), g_CurrentTask->lpSetName ? g_CurrentTask->lpSetName : g_CurrentTask->lpFullPathName, g_CurrentTask->lpSetParam, NULL);
  392. SendDlgItemMessage(hDlg, IDC_LISTSET, LB_RESETCONTENT, 0, 0);
  393. GetCleanupSettings(GetDlgItem(hDlg, IDC_LISTSET));
  394. break;
  395. // Common controls to all pages:
  396. //
  397. case IDC_YES:
  398. case IDC_DENY:
  399. g_CurrentTask->dwOptions ^= TASK_SCHEDULED;
  400. EnableWindow(GetDlgItem(hDlg, IDC_RESCHED), id == IDC_YES);
  401. EnableWindow(GetDlgItem(hDlg, IDC_SETTING), ( id == IDC_YES ) && ( (g_CurrentTask->lpSetName != NULL) || (g_CurrentTask->lpSetParam != NULL) ));
  402. EnableWindow(GetDlgItem(hDlg, IDC_SCHEDTEXT), id == IDC_YES);
  403. break;
  404. case IDC_RESCHED:
  405. // Display the reschedule property sheet.
  406. //
  407. if ( JobReschedule(hDlg, g_CurrentTask->pTask) )
  408. {
  409. // If the schedule change update the display with
  410. // the new trigger string.
  411. //
  412. if ( lpBuffer = GetTaskTriggerText(g_CurrentTask->pTask) )
  413. {
  414. SetWindowText(GetDlgItem(hDlg, IDC_SCHEDTEXT), lpBuffer);
  415. FREE(lpBuffer);
  416. }
  417. }
  418. break;
  419. case IDC_SETTING:
  420. ExecAndWait(GetParent(hDlg), g_CurrentTask->lpSetName ? g_CurrentTask->lpSetName : g_CurrentTask->lpFullPathName, g_CurrentTask->lpSetParam, NULL);
  421. break;
  422. /*
  423. case IDC_SETTING:
  424. nItem = PageContents[g_nPageIdx].nTaskID;
  425. WideCharToMultiByte(CP_ACP, 0, ItemData[nItem].pwFullPathName, -1, szTemp, MAX_PATH, NULL, NULL);
  426. if (nItem == TASK_SMARTTIDY)
  427. SetSmartTidyOption(hDlg);
  428. else {
  429. wsprintf(szParameters, (nItem == TASK_CLEANUP) ? "/TUNEUP:%d" : "/SAGESET:%d",
  430. ItemData[PageContents[g_nPageIdx].nTaskID].nSageID);
  431. ExecAndWait(szTemp, szParameters, g_pWinDir, GetParent(hDlg), TRUE);
  432. }
  433. SetFocus(hDlg);
  434. if (nItem == TASK_CLEANUP) {
  435. }
  436. break;
  437. */
  438. }
  439. }
  440. static BOOL OnDrawItem(HWND hWnd, const DRAWITEMSTRUCT * lpDrawItem)
  441. {
  442. BOOL bReturn;
  443. switch (lpDrawItem->CtlID)
  444. {
  445. case IDC_STARTUP:
  446. bReturn = StartupDrawItem(hWnd, lpDrawItem);
  447. break;
  448. case IDC_SUMLIST:
  449. bReturn = SummaryDrawItem(hWnd, lpDrawItem);
  450. break;
  451. default:
  452. bReturn = FALSE;
  453. }
  454. SetWindowLongPtr(hWnd, DWLP_MSGRESULT, bReturn);
  455. return bReturn;
  456. }
  457. static BOOL OnNotify(HWND hDlg, INT nPageId, INT nCode)
  458. {
  459. BOOL bTest;
  460. LPTSTR lpBuffer;
  461. switch (nCode)
  462. {
  463. case PSN_SETACTIVE:
  464. // Set Back, Next, Finish correctly.
  465. //
  466. PropSheet_SetWizButtons(GetParent(hDlg), (nPageId == IDD_WELCOME ? 0 : PSWIZB_BACK) | ( (nPageId == IDD_SUMMARY) ? PSWIZB_FINISH : PSWIZB_NEXT) );
  467. switch (nPageId)
  468. {
  469. case IDD_WELCOME:
  470. case IDD_BACKUP:
  471. case IDD_STARTMENU:
  472. break;
  473. case IDD_TIME:
  474. EnableWindow(GetDlgItem(hDlg, IDC_CURRENT), !(g_dwFlags & TUNEUP_NOSCHEDULE));
  475. EnableWindow(GetDlgItem(hDlg, IDC_NIGHT), (g_dwFlags & TUNEUP_NOSCHEDULE));
  476. EnableWindow(GetDlgItem(hDlg, IDC_DAY), (g_dwFlags & TUNEUP_NOSCHEDULE));
  477. EnableWindow(GetDlgItem(hDlg, IDC_EVENING), (g_dwFlags & TUNEUP_NOSCHEDULE));
  478. if ( g_dwFlags & TUNEUP_NOSCHEDULE )
  479. CheckRadioButton(hDlg, IDC_CURRENT, IDC_RESET, IDC_RESET);
  480. else
  481. CheckRadioButton(hDlg, IDC_CURRENT, IDC_RESET, IDC_CURRENT);
  482. CheckRadioButton(hDlg, IDC_NIGHT, IDC_EVENING, g_nTimeScheme);
  483. break;
  484. case IDD_SUMMARY:
  485. bTest = ( TasksScheduled(g_Tasks) > 0);
  486. ShowEnableWindow(GetDlgItem(hDlg, IDC_SUMTEXT), bTest);
  487. ShowEnableWindow(GetDlgItem(hDlg, IDC_SUMLIST), bTest);
  488. ShowEnableWindow(GetDlgItem(hDlg, IDC_RUNNOW), bTest);
  489. ShowEnableWindow(GetDlgItem(hDlg, IDC_NOTASKS), !bTest);
  490. if (bTest)
  491. InitSummaryList(GetDlgItem(hDlg, IDC_SUMLIST), g_Tasks);
  492. //LoadString(g_hInst, IDS_REM_NIGHT + g_nTimeScheme - IDC_NIGHT, szTemp, 256);
  493. //SetDlgItemText(hDlg, IDC_REMIND, szTemp);
  494. //InitSummaryList(GetDlgItem(hDlg, IDC_SUMMARYLIST3), nPage);
  495. break;
  496. default:
  497. // Update the task trigger text.
  498. //
  499. if ( lpBuffer = GetTaskTriggerText(g_CurrentTask->pTask) )
  500. {
  501. SetWindowText(GetDlgItem(hDlg, IDC_SCHEDTEXT), lpBuffer);
  502. FREE(lpBuffer);
  503. }
  504. }
  505. break;
  506. case PSN_WIZBACK:
  507. switch (nPageId)
  508. {
  509. case IDD_SUMMARY:
  510. if ( !(g_dwFlags & TUNEUP_CUSTOM) )
  511. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_TIME);
  512. break;
  513. case IDD_WELCOME:
  514. case IDD_TIME:
  515. break;
  516. default:
  517. if (g_CurrentTask->lpBack)
  518. g_CurrentTask = g_CurrentTask->lpBack;
  519. }
  520. break;
  521. case PSN_WIZNEXT:
  522. switch (nPageId)
  523. {
  524. case IDD_TIME:
  525. // Change the time scheme if needed.
  526. //
  527. if ( IsDlgButtonChecked(hDlg, IDC_RESET) )
  528. UpdateTimeScheme(hDlg);
  529. // Set this so that the next time this page is displayed,
  530. // we know there is already a schedule.
  531. //
  532. g_dwFlags &= ~TUNEUP_NOSCHEDULE;
  533. // Jump right to the summary page if we are in
  534. // express mode.
  535. //
  536. if ( !(g_dwFlags & TUNEUP_CUSTOM) )
  537. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, IDD_SUMMARY);
  538. break;
  539. case IDD_WELCOME:
  540. case IDD_STARTMENU:
  541. case IDD_SUMMARY:
  542. break;
  543. default:
  544. if (g_CurrentTask->lpNext)
  545. g_CurrentTask = g_CurrentTask->lpNext;
  546. }
  547. break;
  548. case PSN_WIZFINISH:
  549. // Set this flag so that we know to save settings (like
  550. // cleaning up the startup groups).
  551. //
  552. g_dwFlags |= TUNEUP_FINISHED;
  553. ReleaseJobs(g_Tasks, g_dwFlags & TUNEUP_FINISHED);
  554. // Save the registry settings.
  555. //
  556. RegSetString(HKLM, g_szTuneupKey, g_szRegValFirstTime, _T("1"));
  557. RegSetDword(HKLM, g_szTuneupKey, g_szRegValTime, g_nTimeScheme);
  558. RegSetString(HKLM, g_szTuneupKey, g_szRegValCustom, (g_dwFlags & TUNEUP_CUSTOM) ? _T("1") : _T("0"));
  559. // Run the tasks now if the box is checked.
  560. //
  561. if ( IsDlgButtonChecked(hDlg, IDC_RUNNOW) && (TasksScheduled(g_Tasks) > 0) )
  562. RunTasksNow(GetParent(hDlg), g_Tasks);
  563. // Launch backup if we wanted to.
  564. //
  565. if ( g_dwFlags & TUNEUP_RUNBACKUP )
  566. ExecAndWait(GetParent(hDlg), g_szBackupExe, NULL, NULL);
  567. break;
  568. case PSN_QUERYCANCEL:
  569. // Now release the jobs, saving each one if we fell
  570. // through the above PSN_WIZFINISH.
  571. //
  572. ReleaseJobs(g_Tasks, g_dwFlags & TUNEUP_FINISHED);
  573. break;
  574. /*
  575. if ( (nPage == PAGE_TIME) && (g_nTimeScheme != IDC_CUSTOM) )
  576. // keep the init status; we may need to reset the time scheme when leave this page,
  577. nOrgTimeScheme = g_nTimeScheme = GetTimeScheme();
  578. ActivateWizardPage(hDlg, nPage);
  579. g_nPageIdx = nPage;
  580. case PSN_WIZFINISH:
  581. // start Task Scheduler if any item is scheduled
  582. if (IsAnythingScheduled()) {
  583. // Add the Key for restarting computer
  584. static TCHAR szKey[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunServices";
  585. HKEY hKey;
  586. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  587. RegSetValueEx(hKey, (LPCTSTR)"SchedulingAgent", 0, REG_SZ, (LPBYTE)"mstask.exe", 11);
  588. RegCloseKey(hKey);
  589. }
  590. StartScheduler();
  591. }
  592. // do all non-scheduled stuff, or run now...
  593. PerformAction(hDlg, IsDlgButtonChecked(hDlg, IDC_RUN_NOW));
  594. // release all TaskScheduler interface/method, cal IPersist->save to write it
  595. ReleaseJob(TRUE);
  596. break;
  597. */
  598. default:
  599. return FALSE;
  600. }
  601. return TRUE;
  602. }
  603. static VOID InitBoldFont(HWND hWndCtrl)
  604. {
  605. static HFONT hBigFont = NULL;
  606. TCHAR szFontName[32];
  607. DWORD dwFontSize;
  608. // If NULL is passed in, we should free the font handle.
  609. //
  610. if ( hWndCtrl == NULL )
  611. {
  612. // Free the font handle.
  613. //
  614. if (hBigFont)
  615. DeleteObject(hBigFont);
  616. }
  617. else
  618. {
  619. // We may already have the handle to the font we need,
  620. // but if not, we need to get it.
  621. //
  622. if ( hBigFont == NULL )
  623. {
  624. // Get the font size.
  625. //
  626. if ( LoadString(NULL, IDS_TITLEFONTSIZE, szFontName, sizeof(szFontName) / sizeof(TCHAR)) )
  627. dwFontSize = _tcstoul(szFontName, NULL, 10);
  628. else
  629. dwFontSize = 12;
  630. // Get the font name.
  631. //
  632. if ( !LoadString(NULL, IDS_TITLEFONTNAME, szFontName, sizeof(szFontName) / sizeof(TCHAR)) )
  633. lstrcpy(szFontName, _T("Verdana"));
  634. hBigFont = GetFont(hWndCtrl, szFontName, dwFontSize, FW_BOLD);
  635. }
  636. // Now send the font to the control.
  637. //
  638. if ( hBigFont )
  639. SendMessage(hWndCtrl, WM_SETFONT, (WPARAM) hBigFont, MAKELPARAM(TRUE, 0));
  640. }
  641. }
  642. static VOID FreeWizPages(LPWIZPAGE lpWizPage)
  643. {
  644. if (lpWizPage)
  645. {
  646. FreeWizPages(lpWizPage->lpNext);
  647. FREE(lpWizPage);
  648. }
  649. }
  650. static LPWIZPAGE CreateWizPage(LPWIZPAGE lpWizPage, INT iDialog, LPTSTR lpTitle, LPTSTR lpSubTitle)
  651. {
  652. if ( lpWizPage->lpNext = (LPWIZPAGE) MALLOC(sizeof(WIZPAGE)) )
  653. {
  654. lpWizPage = lpWizPage->lpNext;
  655. lpWizPage->iDialog = iDialog;
  656. lpWizPage->lpTitle = lpTitle;
  657. lpWizPage->lpSubTitle = lpSubTitle;
  658. }
  659. return lpWizPage;
  660. }