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.

488 lines
15 KiB

  1. // ***************************************************************************
  2. #include "pch.h"
  3. #pragma hdrstop
  4. #include "resource.h"
  5. #include "wizard.h"
  6. #include "ncreg.h"
  7. #include "ncui.h"
  8. extern const WCHAR c_szEmpty[];
  9. // ***************************************************************************
  10. // Function: SetupFonts
  11. //
  12. // Purpose: Generate bold or large bold fonts based on the font of the
  13. // window specified
  14. //
  15. // Parameters: hwnd [IN] - Handle of window to base font on
  16. // pBoldFont [OUT] - The newly generated font, NULL if the
  17. // font could not be generated
  18. // fLargeFont [IN] - If TRUE, generate a 12 point bold font for
  19. // use in the wizard "welcome" page.
  20. //
  21. // Returns: nothing
  22. // ***************************************************************************
  23. VOID SetupFonts(HWND hwnd, HFONT * pBoldFont, BOOL fLargeFont)
  24. {
  25. TraceFileFunc(ttidGuiModeSetup);
  26. LOGFONT BoldLogFont;
  27. HFONT hFont;
  28. WCHAR FontSizeString[MAX_PATH];
  29. INT FontSize;
  30. Assert(pBoldFont);
  31. *pBoldFont = NULL;
  32. // Get the font used by the specified window
  33. hFont = (HFONT)::SendMessage(hwnd, WM_GETFONT, 0, 0L);
  34. if (NULL == hFont)
  35. {
  36. // If not found then the control is using the system font
  37. hFont = (HFONT)GetStockObject(SYSTEM_FONT);
  38. }
  39. if (hFont)
  40. {
  41. // Get the font info so we can generate the BOLD version
  42. if (GetObject(hFont, sizeof(BoldLogFont), &BoldLogFont))
  43. {
  44. // Create the Bold Font
  45. BoldLogFont.lfWeight = FW_BOLD;
  46. HDC hdc = GetDC(hwnd);
  47. if (hdc)
  48. {
  49. // Large (tall) font is an option
  50. if (fLargeFont)
  51. {
  52. // Load size and name from resources, since these may change
  53. // from locale to locale based on the size of the system font, etc.
  54. UINT nLen = lstrlenW(SzLoadIds(IDS_LARGEFONTNAME));
  55. if ((0 < nLen) && (nLen < LF_FACESIZE))
  56. {
  57. lstrcpyW(BoldLogFont.lfFaceName,SzLoadIds(IDS_LARGEFONTNAME));
  58. }
  59. FontSize = 12;
  60. nLen = lstrlen(SzLoadIds(IDS_LARGEFONTSIZE));
  61. if ((nLen < celems(FontSizeString)) && (0 < nLen))
  62. {
  63. lstrcpyW(FontSizeString, SzLoadIds(IDS_LARGEFONTSIZE));
  64. FontSize = wcstoul(FontSizeString, NULL, 10);
  65. }
  66. BoldLogFont.lfHeight = 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * FontSize / 72);
  67. }
  68. *pBoldFont = CreateFontIndirect(&BoldLogFont);
  69. ReleaseDC(hwnd, hdc);
  70. }
  71. }
  72. }
  73. }
  74. // ***************************************************************************
  75. VOID CenterWizard(HWND hwndDlg)
  76. {
  77. TraceFileFunc(ttidGuiModeSetup);
  78. RECT rc;
  79. int nWidth = GetSystemMetrics(SM_CXSCREEN);
  80. int nHeight = GetSystemMetrics(SM_CYSCREEN);
  81. GetWindowRect(hwndDlg, &rc);
  82. SetWindowPos(hwndDlg, NULL,
  83. ((nWidth / 2) - ((rc.right - rc.left) / 2)),
  84. ((nHeight / 2) - ((rc.bottom - rc.top) / 2)),
  85. 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
  86. }
  87. // ***************************************************************************
  88. // Function: OnMainPageActivate
  89. //
  90. // Purpose: Handle the PSN_SETACTIVE notification
  91. //
  92. // Parameters: hwndDlg [IN] - Handle to the Main dialog
  93. //
  94. // Returns: BOOL
  95. // ***************************************************************************
  96. BOOL OnMainPageActivate(HWND hwndDlg)
  97. {
  98. TraceFileFunc(ttidGuiModeSetup);
  99. TraceTag(ttidWizard, "Entering Main Menu page...");
  100. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 0L);
  101. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  102. return TRUE;
  103. }
  104. RECT RectTranslateLocal(RECT rcContainee, RECT rcContainer)
  105. {
  106. Assert(rcContainee.left >= rcContainer.left);
  107. Assert(rcContainee.top >= rcContainer.top);
  108. Assert(rcContainee.right <= rcContainer.right);
  109. Assert(rcContainee.bottom <= rcContainer.bottom);
  110. // e.g. 10,10,100,100
  111. // inside 5, 5,110,110
  112. // should give: 5,5,95,95
  113. RECT rcTemp;
  114. rcTemp.left = rcContainee.left - rcContainer.left;
  115. rcTemp.top = rcContainee.top - rcContainer.top;
  116. rcTemp.right = rcContainee.right - rcContainer.left;
  117. rcTemp.bottom = rcContainee.bottom - rcContainer.top;
  118. return rcTemp;
  119. }
  120. // ***************************************************************************
  121. // Function: OnMainDialogInit
  122. //
  123. // Purpose: Handle the WM_INITDIALOG notification
  124. //
  125. // Parameters: hwndDlg [IN] - Handle to the Main dialog
  126. // lParam [IN] -
  127. //
  128. // Returns: BOOL
  129. // ***************************************************************************
  130. BOOL OnMainDialogInit(HWND hwndDlg, LPARAM lParam)
  131. {
  132. TraceFileFunc(ttidGuiModeSetup);
  133. INT nIdx;
  134. // The order here should be the same as the vertical order in the resources
  135. INT nrgChks[] = {CHK_MAIN_INTERNET_CONNECTION, CHK_MAIN_CONNECTION, CHK_MAIN_HOMENET, CHK_MAIN_ADVANCED};
  136. if (S_OK != HrShouldHaveHomeNetWizard())
  137. {
  138. HWND hwndCHK_MAIN_HOMENET = GetDlgItem(hwndDlg, CHK_MAIN_HOMENET);
  139. HWND hwndTXT_MAIN_HOMENET = GetDlgItem(hwndDlg, TXT_MAIN_HOMENET);
  140. HWND hwndCHK_MAIN_ADVANCED = GetDlgItem(hwndDlg, CHK_MAIN_ADVANCED);
  141. HWND hwndTXT_MAIN_ADVANCED_1= GetDlgItem(hwndDlg, TXT_MAIN_ADVANCED_1);
  142. EnableWindow(hwndCHK_MAIN_HOMENET, FALSE);
  143. ShowWindow(hwndCHK_MAIN_HOMENET, SW_HIDE);
  144. ShowWindow(hwndTXT_MAIN_HOMENET, SW_HIDE);
  145. RECT rcHomeNetChk;
  146. RECT rcAdvanceChk;
  147. RECT rcAdvanceTxt;
  148. RECT rcDialog;
  149. GetWindowRect(hwndCHK_MAIN_HOMENET, &rcHomeNetChk);
  150. GetWindowRect(hwndCHK_MAIN_ADVANCED, &rcAdvanceChk);
  151. GetWindowRect(hwndTXT_MAIN_ADVANCED_1, &rcAdvanceTxt);
  152. GetWindowRect(hwndDlg, &rcDialog);
  153. DWORD dwMoveUpBy = rcAdvanceChk.top - rcHomeNetChk.top;
  154. rcAdvanceChk.top -= dwMoveUpBy;
  155. rcAdvanceChk.bottom -= dwMoveUpBy;
  156. rcAdvanceTxt.top -= dwMoveUpBy;
  157. rcAdvanceTxt.bottom -= dwMoveUpBy;
  158. Assert(rcAdvanceChk.top == rcHomeNetChk.top);
  159. rcAdvanceChk = RectTranslateLocal(rcAdvanceChk, rcDialog);
  160. rcAdvanceTxt = RectTranslateLocal(rcAdvanceTxt, rcDialog);
  161. MoveWindow(hwndCHK_MAIN_ADVANCED, rcAdvanceChk.left, rcAdvanceChk.top, rcAdvanceChk.right - rcAdvanceChk.left, rcAdvanceChk.bottom - rcAdvanceChk.top, TRUE);
  162. MoveWindow(hwndTXT_MAIN_ADVANCED_1, rcAdvanceTxt.left, rcAdvanceTxt.top, rcAdvanceTxt.right - rcAdvanceTxt.left, rcAdvanceTxt.bottom - rcAdvanceTxt.top, TRUE);
  163. }
  164. // Initialize our pointers to property sheet info.
  165. PROPSHEETPAGE* psp = (PROPSHEETPAGE*)lParam;
  166. Assert(psp->lParam);
  167. ::SetWindowLongPtr(hwndDlg, DWLP_USER, psp->lParam);
  168. CWizard * pWizard = reinterpret_cast<CWizard *>(psp->lParam);
  169. Assert(NULL != pWizard);
  170. // Get the bold font for the radio buttons
  171. HFONT hBoldFont = NULL;
  172. SetupFonts(hwndDlg, &hBoldFont, FALSE);
  173. if (NULL != hBoldFont)
  174. {
  175. // Remember the font handle so we can free it on exit
  176. pWizard->SetPageData(IDD_Main, (LPARAM)hBoldFont);
  177. for (nIdx = 0; nIdx < celems(nrgChks); nIdx++)
  178. {
  179. HWND hwndCtl = GetDlgItem(hwndDlg, nrgChks[nIdx]);
  180. Assert(NULL != hwndCtl);
  181. SetWindowFont(hwndCtl, hBoldFont, TRUE);
  182. }
  183. }
  184. // Find the top most enabled radio button
  185. for (nIdx = 0; nIdx < celems(nrgChks); nIdx++)
  186. {
  187. if (IsWindowEnabled(GetDlgItem(hwndDlg, nrgChks[nIdx])))
  188. {
  189. CheckRadioButton(hwndDlg, CHK_MAIN_INTERNET_CONNECTION, CHK_MAIN_ADVANCED, nrgChks[nIdx]);
  190. break;
  191. }
  192. }
  193. return TRUE;
  194. }
  195. // ***************************************************************************
  196. // Function: OnMainWizNext
  197. //
  198. // Purpose: Handle the PSN_WIZNEXT notification
  199. //
  200. // Parameters: hwndDlg [IN] - Handle to the Main dialog
  201. //
  202. // Returns: BOOL
  203. // ***************************************************************************
  204. BOOL OnMainWizNext(HWND hwndDlg)
  205. {
  206. TraceFileFunc(ttidGuiModeSetup);
  207. tstring str;
  208. // Retrieve the CWizard instance from the dialog
  209. CWizard * pWizard =
  210. reinterpret_cast<CWizard *>(::GetWindowLongPtr(hwndDlg, DWLP_USER));
  211. Assert(NULL != pWizard);
  212. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  213. if ( ! IsPostInstall(pWizard) || (0 == pWizard->UlProviderCount()))
  214. {
  215. return TRUE;
  216. }
  217. if (IsDlgButtonChecked(hwndDlg, CHK_MAIN_INTERNET_CONNECTION) == BST_CHECKED)
  218. {
  219. pWizard->SetPageOrigin(IDD_ISP, IDD_Main, CHK_MAIN_INTERNET_CONNECTION);
  220. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_ISP);
  221. }
  222. else if (IsDlgButtonChecked(hwndDlg, CHK_MAIN_CONNECTION) == BST_CHECKED)
  223. {
  224. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_Connect);
  225. }
  226. else if (IsDlgButtonChecked(hwndDlg, CHK_MAIN_HOMENET) == BST_CHECKED)
  227. {
  228. pWizard->SetPageOrigin(IDD_FinishNetworkSetupWizard, IDD_Main, CHK_ISP_OTHER_WAYS);
  229. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_FinishNetworkSetupWizard);
  230. }
  231. else
  232. {
  233. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_Advanced);
  234. }
  235. return TRUE;
  236. }
  237. // ***************************************************************************
  238. // Function: dlgprocMain
  239. //
  240. // Purpose: Dialog Procedure for the Main wizard page
  241. //
  242. // Parameters: standard dlgproc parameters
  243. //
  244. // Returns: INT_PTR
  245. // ***************************************************************************
  246. INT_PTR CALLBACK dlgprocMain(HWND hwndDlg, UINT uMsg,
  247. WPARAM wParam, LPARAM lParam)
  248. {
  249. TraceFileFunc(ttidGuiModeSetup);
  250. BOOL frt = FALSE;
  251. switch (uMsg)
  252. {
  253. case WM_INITDIALOG:
  254. frt = OnMainDialogInit(hwndDlg, lParam);
  255. break;
  256. case WM_NOTIFY:
  257. {
  258. LPNMHDR pnmh = (LPNMHDR)lParam;
  259. switch (pnmh->code)
  260. {
  261. // propsheet notification
  262. case PSN_HELP:
  263. break;
  264. case PSN_SETACTIVE:
  265. frt = OnMainPageActivate(hwndDlg);
  266. break;
  267. case PSN_APPLY:
  268. break;
  269. case PSN_KILLACTIVE:
  270. break;
  271. case PSN_RESET:
  272. break;
  273. case PSN_WIZBACK:
  274. break;
  275. case PSN_WIZFINISH:
  276. break;
  277. case PSN_WIZNEXT:
  278. frt = OnMainWizNext(hwndDlg);
  279. break;
  280. default:
  281. break;
  282. }
  283. }
  284. break;
  285. default:
  286. break;
  287. }
  288. return( frt );
  289. }
  290. // ***************************************************************************
  291. // Function: MainPageCleanup
  292. //
  293. // Purpose: As a callback function to allow any page allocated memory
  294. // to be cleaned up, after the page will no longer be accessed.
  295. //
  296. // Parameters: pWizard [IN] - The wizard against which the page called
  297. // register page
  298. // lParam [IN] - The lParam supplied in the RegisterPage call
  299. //
  300. // Returns: nothing
  301. // ***************************************************************************
  302. VOID MainPageCleanup(CWizard *pWizard, LPARAM lParam)
  303. {
  304. TraceFileFunc(ttidGuiModeSetup);
  305. HFONT hBoldFont = (HFONT)pWizard->GetPageData(IDD_Main);
  306. if (NULL != hBoldFont)
  307. {
  308. DeleteObject(hBoldFont);
  309. }
  310. }
  311. // ***************************************************************************
  312. // Function: CreateMainPage
  313. //
  314. // Purpose: To determine if the Main page needs to be shown, and to
  315. // to create the page if requested. Note the Main page is
  316. // responsible for initial installs also.
  317. //
  318. // Parameters: pWizard [IN] - Ptr to a Wizard instance
  319. // pData [IN] - Context data to describe the world in
  320. // which the Wizard will be run
  321. // fCountOnly [IN] - If True, only the maximum number of
  322. // pages this routine will create need
  323. // be determined.
  324. // pnPages [IN] - Increment by the number of pages
  325. // to create/created
  326. //
  327. // Returns: HRESULT, S_OK on success
  328. // ***************************************************************************
  329. HRESULT HrCreateMainPage(CWizard *pWizard, PINTERNAL_SETUP_DATA pData,
  330. BOOL fCountOnly, UINT *pnPages)
  331. {
  332. TraceFileFunc(ttidGuiModeSetup);
  333. HRESULT hr = S_OK;
  334. if (IsPostInstall(pWizard) && ( ! pWizard->FProcessLanPages()))
  335. {
  336. // RAS PostInstall only
  337. (*pnPages)++;
  338. // If not only counting, create and register the page
  339. if ( ! fCountOnly)
  340. {
  341. HPROPSHEETPAGE hpsp;
  342. PROPSHEETPAGE psp;
  343. TraceTag(ttidWizard, "Creating Main Page");
  344. psp.dwSize = sizeof( PROPSHEETPAGE );
  345. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  346. psp.hInstance = _Module.GetResourceInstance();
  347. psp.pszTemplate = MAKEINTRESOURCE( IDD_Main );
  348. psp.hIcon = NULL;
  349. psp.pfnDlgProc = dlgprocMain;
  350. psp.lParam = reinterpret_cast<LPARAM>(pWizard);
  351. psp.pszHeaderTitle = SzLoadIds(IDS_T_Main);
  352. psp.pszHeaderSubTitle = SzLoadIds(IDS_ST_Main);
  353. hpsp = CreatePropertySheetPage( &psp );
  354. if (hpsp)
  355. {
  356. pWizard->RegisterPage(IDD_Main, hpsp,
  357. MainPageCleanup, NULL);
  358. }
  359. else
  360. {
  361. hr = E_OUTOFMEMORY;
  362. }
  363. }
  364. }
  365. TraceHr(ttidWizard, FAL, hr, FALSE, "HrCreateMainPage");
  366. return hr;
  367. }
  368. // ***************************************************************************
  369. // Function: AppendMainPage
  370. //
  371. // Purpose: Add the Main page, if it was created, to the set of pages
  372. // that will be displayed.
  373. //
  374. // Parameters: pWizard [IN] - Ptr to Wizard Instance
  375. // pahpsp [IN,OUT] - Array of pages to add our page to
  376. // pcPages [IN,OUT] - Count of pages in pahpsp
  377. //
  378. // Returns: Nothing
  379. // ***************************************************************************
  380. VOID AppendMainPage(CWizard *pWizard, HPROPSHEETPAGE* pahpsp, UINT *pcPages)
  381. {
  382. TraceFileFunc(ttidGuiModeSetup);
  383. if (IsPostInstall(pWizard) && ( ! pWizard->FProcessLanPages()))
  384. {
  385. HPROPSHEETPAGE hPage = pWizard->GetPageHandle(IDD_Main);
  386. Assert(hPage);
  387. pahpsp[*pcPages] = hPage;
  388. (*pcPages)++;
  389. }
  390. }
  391. // ***************************************************************************