Leaked source code of windows server 2003
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.

497 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. #include <ncperms.h>
  9. static const CLSID CLSID_InboundConnection =
  10. {0xBA126AD9,0x2166,0x11D1,{0xB1,0xD0,0x00,0x80,0x5F,0xC1,0x27,0x0E}};
  11. extern const WCHAR c_szEmpty[];
  12. // ***************************************************************************
  13. // Function: SetupFonts
  14. //
  15. // Purpose: Generate bold or large bold fonts based on the font of the
  16. // window specified
  17. //
  18. // Parameters: hwnd [IN] - Handle of window to base font on
  19. // pBoldFont [OUT] - The newly generated font, NULL if the
  20. // font could not be generated
  21. // fLargeFont [IN] - If TRUE, generate a 12 point bold font for
  22. // use in the wizard "welcome" page.
  23. //
  24. // Returns: nothing
  25. // ***************************************************************************
  26. VOID SetupAdvancedFonts(HWND hwnd, HFONT * pBoldFont, BOOL fLargeFont)
  27. {
  28. LOGFONT BoldLogFont;
  29. HFONT hFont;
  30. WCHAR FontSizeString[MAX_PATH];
  31. INT FontSize;
  32. Assert(pBoldFont);
  33. *pBoldFont = NULL;
  34. // Get the font used by the specified window
  35. hFont = (HFONT)::SendMessage(hwnd, WM_GETFONT, 0, 0L);
  36. if (NULL == hFont)
  37. {
  38. // If not found then the control is using the system font
  39. hFont = (HFONT)GetStockObject(SYSTEM_FONT);
  40. }
  41. if (hFont)
  42. {
  43. // Get the font info so we can generate the BOLD version
  44. if (GetObject(hFont, sizeof(BoldLogFont), &BoldLogFont))
  45. {
  46. // Create the Bold Font
  47. //
  48. BoldLogFont.lfWeight = FW_BOLD;
  49. HDC hdc = GetDC(hwnd);
  50. if (hdc)
  51. {
  52. // Large (tall) font is an option
  53. if (fLargeFont)
  54. {
  55. // Load size and name from resources, since these may change
  56. // from locale to locale based on the size of the system font, etc.
  57. UINT nLen = lstrlenW(SzLoadIds(IDS_LARGEFONTNAME));
  58. if ((0 < nLen) && (nLen < LF_FACESIZE))
  59. {
  60. lstrcpyW(BoldLogFont.lfFaceName,SzLoadIds(IDS_LARGEFONTNAME));
  61. }
  62. FontSize = 12;
  63. nLen = lstrlen(SzLoadIds(IDS_LARGEFONTSIZE));
  64. if ((nLen < celems(FontSizeString)) && (0 < nLen))
  65. {
  66. lstrcpyW(FontSizeString, SzLoadIds(IDS_LARGEFONTSIZE));
  67. FontSize = wcstoul(FontSizeString, NULL, 10);
  68. }
  69. BoldLogFont.lfHeight = 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * FontSize / 72);
  70. }
  71. *pBoldFont = CreateFontIndirect(&BoldLogFont);
  72. ReleaseDC(hwnd, hdc);
  73. }
  74. }
  75. }
  76. }
  77. // ***************************************************************************
  78. // Function: AlreadyHaveIncomingConnection
  79. //
  80. // Purpose: Check if there are any inbound connections already
  81. //
  82. // Returns: TRUE - there is one
  83. // FALSE - none
  84. // ***************************************************************************
  85. BOOL AlreadyHaveIncomingConnection(CWizard* pWizard)
  86. {
  87. HRESULT hr;
  88. BOOL ret = FALSE;
  89. INetConnectionManager * pConnectionMgr = NULL;
  90. hr = CoCreateInstance(CLSID_ConnectionManager, NULL,
  91. CLSCTX_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  92. IID_INetConnectionManager,
  93. (LPVOID *)&pConnectionMgr);
  94. if (SUCCEEDED(hr))
  95. {
  96. IEnumNetConnection* pEnum;
  97. hr = pConnectionMgr->EnumConnections(NCME_DEFAULT, &pEnum);
  98. if (SUCCEEDED(hr))
  99. {
  100. INetConnection* aNetCon [512];
  101. ULONG cNetCon;
  102. hr = pEnum->Next (celems(aNetCon), aNetCon, &cNetCon);
  103. if (SUCCEEDED(hr))
  104. {
  105. for (ULONG i = 0; (i < cNetCon) && (ret == FALSE); i++)
  106. {
  107. INetConnection* pNetCon = aNetCon[i];
  108. NETCON_PROPERTIES* pProps;
  109. hr = pNetCon->GetProperties (&pProps);
  110. if (SUCCEEDED(hr))
  111. {
  112. if (pWizard->CompareCLSID(pProps->clsidThisObject, CLSID_InboundConnection) == TRUE)
  113. {
  114. ret = TRUE;
  115. }
  116. CoTaskMemFree(pProps);
  117. }
  118. ReleaseObj (pNetCon);
  119. }
  120. }
  121. pEnum->Release();
  122. }
  123. pConnectionMgr->Release();
  124. }
  125. return(ret);
  126. }
  127. // ***************************************************************************
  128. // Function: OnAdvancedPageActivate
  129. //
  130. // Purpose: Handle the PSN_SETACTIVE notification
  131. //
  132. // Parameters: hwndDlg [IN] - Handle to the Main dialog
  133. //
  134. // Returns: BOOL
  135. // ***************************************************************************
  136. BOOL OnAdvancedPageActivate(HWND hwndDlg)
  137. {
  138. TraceTag(ttidWizard, "Entering Advanced Menu page...");
  139. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 0L);
  140. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  141. return TRUE;
  142. }
  143. // ***************************************************************************
  144. // Function: OnAdvancedWizNext
  145. //
  146. // Purpose: Handle the PSN_WIZNEXT notification
  147. //
  148. // Parameters: hwndDlg [IN] - Handle to the Main dialog
  149. //
  150. // Returns: BOOL
  151. // ***************************************************************************
  152. BOOL OnAdvancedWizNext(HWND hwndDlg)
  153. {
  154. // Retrieve the CWizard instance from the dialog
  155. CWizard * pWizard =
  156. reinterpret_cast<CWizard *>(::GetWindowLongPtr(hwndDlg, DWLP_USER));
  157. Assert(NULL != pWizard);
  158. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  159. if ( ! IsPostInstall(pWizard) || (0 == pWizard->UlProviderCount()))
  160. {
  161. return TRUE;
  162. }
  163. // Find the selected provider and go to it's first page
  164. for (ULONG ulIdx = 0; ulIdx < pWizard->UlProviderCount(); ulIdx++)
  165. {
  166. CWizProvider * pWizProvider = pWizard->PWizProviders(ulIdx);
  167. Assert(NULL != pWizProvider);
  168. Assert(0 != pWizProvider->ULPageCount());
  169. if (IsDlgButtonChecked(hwndDlg, pWizProvider->GetBtnIdc()))
  170. {
  171. pWizard->SetCurrentProvider(ulIdx);
  172. HPROPSHEETPAGE hPage = (pWizProvider->PHPropPages())[0];
  173. Assert(NULL != hPage);
  174. PostMessage(GetParent(hwndDlg), PSM_SETCURSEL, 0,
  175. (LPARAM)(HPROPSHEETPAGE)hPage);
  176. }
  177. }
  178. return TRUE;
  179. }
  180. // ***************************************************************************
  181. BOOL OnAdvancedDialogInit(HWND hwndDlg, LPARAM lParam)
  182. {
  183. INT nIdx;
  184. INT nrgIdc[] = {CHK_MAIN_INBOUND, TXT_MAIN_INBOUND_1,
  185. CHK_MAIN_DIRECT, TXT_MAIN_DIRECT_1};
  186. // The order here should be the same as the vertical order in the resources
  187. INT nrgChks[] = {CHK_MAIN_INBOUND, CHK_MAIN_DIRECT};
  188. // Initialize our pointers to property sheet info.
  189. PROPSHEETPAGE* psp = (PROPSHEETPAGE*)lParam;
  190. Assert(psp->lParam);
  191. ::SetWindowLongPtr(hwndDlg, DWLP_USER, psp->lParam);
  192. CWizard * pWizard = reinterpret_cast<CWizard *>(psp->lParam);
  193. Assert(NULL != pWizard);
  194. // Get the bold font for the radio buttons
  195. HFONT hBoldFont = NULL;
  196. SetupAdvancedFonts(hwndDlg, &hBoldFont, FALSE);
  197. if (NULL != hBoldFont)
  198. {
  199. // Remember the font handle so we can free it on exit
  200. pWizard->SetPageData(IDD_Main, (LPARAM)hBoldFont);
  201. for (nIdx = 0; nIdx < celems(nrgChks); nIdx++)
  202. {
  203. HWND hwndCtl = GetDlgItem(hwndDlg, nrgChks[nIdx]);
  204. Assert(NULL != hwndCtl);
  205. SetWindowFont(hwndCtl, hBoldFont, TRUE);
  206. }
  207. }
  208. // Populate the UI
  209. //
  210. for (ULONG ulIdx = 0;
  211. ulIdx < pWizard->UlProviderCount();
  212. ulIdx++)
  213. {
  214. CWizProvider * pWizProvider = pWizard->PWizProviders(ulIdx);
  215. Assert(NULL != pWizProvider);
  216. Assert(0 != pWizProvider->ULPageCount());
  217. // Get the radio button associated with this provider
  218. INT nIdcBtn = pWizProvider->GetBtnIdc();
  219. // Find the set of controls to enable in the array
  220. for (nIdx = 0; nIdx < celems(nrgIdc); nIdx+=2)
  221. {
  222. if (nrgIdc[nIdx] == nIdcBtn)
  223. {
  224. // Enable the controls
  225. for (INT un = 0; un < 2; un++)
  226. {
  227. HWND hwndBtn = GetDlgItem(hwndDlg, nrgIdc[nIdx + un]);
  228. Assert(NULL != hwndBtn);
  229. EnableWindow(hwndBtn, TRUE);
  230. }
  231. break;
  232. }
  233. }
  234. }
  235. if (!FIsUserAdmin())
  236. {
  237. EnableWindow(GetDlgItem(hwndDlg, CHK_MAIN_INBOUND), FALSE);
  238. }
  239. // Find the top most enabled radio button
  240. for (nIdx = 0; nIdx < celems(nrgChks); nIdx++)
  241. {
  242. if (IsWindowEnabled(GetDlgItem(hwndDlg, nrgChks[nIdx])))
  243. {
  244. CheckRadioButton(hwndDlg, CHK_MAIN_INBOUND, CHK_MAIN_DIRECT, nrgChks[nIdx]);
  245. break;
  246. }
  247. }
  248. return TRUE;
  249. }
  250. // ***************************************************************************
  251. // Function: dlgprocAdvanced
  252. //
  253. // Purpose: Dialog Procedure for the Advanced wizard page
  254. //
  255. // Parameters: standard dlgproc parameters
  256. //
  257. // Returns: INT_PTR
  258. // ***************************************************************************
  259. INT_PTR CALLBACK dlgprocAdvanced( HWND hwndDlg, UINT uMsg,
  260. WPARAM wParam, LPARAM lParam )
  261. {
  262. BOOL frt = FALSE;
  263. switch (uMsg)
  264. {
  265. case WM_INITDIALOG:
  266. frt = OnAdvancedDialogInit(hwndDlg, lParam);
  267. break;
  268. case WM_NOTIFY:
  269. {
  270. LPNMHDR pnmh = (LPNMHDR)lParam;
  271. switch (pnmh->code)
  272. {
  273. // propsheet notification
  274. case PSN_HELP:
  275. break;
  276. case PSN_SETACTIVE:
  277. frt = OnAdvancedPageActivate(hwndDlg);
  278. break;
  279. case PSN_APPLY:
  280. break;
  281. case PSN_KILLACTIVE:
  282. break;
  283. case PSN_RESET:
  284. break;
  285. case PSN_WIZBACK:
  286. ::SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_Main);
  287. return(TRUE);
  288. case PSN_WIZFINISH:
  289. break;
  290. case PSN_WIZNEXT:
  291. frt = OnAdvancedWizNext(hwndDlg);
  292. break;
  293. default:
  294. break;
  295. }
  296. }
  297. break;
  298. default:
  299. break;
  300. }
  301. return( frt );
  302. }
  303. // ***************************************************************************
  304. // Function: AdvancedPageCleanup
  305. //
  306. // Purpose: As a callback function to allow any page allocated memory
  307. // to be cleaned up, after the page will no longer be accessed.
  308. //
  309. // Parameters: pWizard [IN] - The wizard against which the page called
  310. // register page
  311. // lParam [IN] - The lParam supplied in the RegisterPage call
  312. //
  313. // Returns: nothing
  314. // ***************************************************************************
  315. VOID AdvancedPageCleanup(CWizard *pWizard, LPARAM lParam)
  316. {
  317. HFONT hBoldFont = (HFONT)pWizard->GetPageData(IDD_Advanced);
  318. if (NULL != hBoldFont)
  319. {
  320. DeleteObject(hBoldFont);
  321. }
  322. }
  323. // ***************************************************************************
  324. // Function: CreateMainPage
  325. //
  326. // Purpose: To determine if the Main page needs to be shown, and to
  327. // to create the page if requested. Note the Main page is
  328. // responsible for initial installs also.
  329. //
  330. // Parameters: pWizard [IN] - Ptr to a Wizard instance
  331. // pData [IN] - Context data to describe the world in
  332. // which the Wizard will be run
  333. // fCountOnly [IN] - If True, only the maximum number of
  334. // pages this routine will create need
  335. // be determined.
  336. // pnPages [IN] - Increment by the number of pages
  337. // to create/created
  338. //
  339. // Returns: HRESULT, S_OK on success
  340. // ***************************************************************************
  341. HRESULT HrCreateAdvancedPage(CWizard *pWizard, PINTERNAL_SETUP_DATA pData,
  342. BOOL fCountOnly, UINT *pnPages)
  343. {
  344. HRESULT hr = S_OK;
  345. if (IsPostInstall(pWizard) && ( ! pWizard->FProcessLanPages()))
  346. {
  347. // RAS PostInstall only
  348. (*pnPages)++;
  349. // If not only counting, create and register the page
  350. if ( ! fCountOnly)
  351. {
  352. HPROPSHEETPAGE hpsp;
  353. PROPSHEETPAGE psp;
  354. TraceTag(ttidWizard, "Creating Advanced Page");
  355. psp.dwSize = sizeof( PROPSHEETPAGE );
  356. psp.dwFlags = PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
  357. psp.hInstance = _Module.GetResourceInstance();
  358. psp.pszTemplate = MAKEINTRESOURCE( IDD_Advanced );
  359. psp.hIcon = NULL;
  360. psp.pfnDlgProc = dlgprocAdvanced;
  361. psp.lParam = reinterpret_cast<LPARAM>(pWizard);
  362. psp.pszHeaderTitle = SzLoadIds(IDS_T_Advanced);
  363. psp.pszHeaderSubTitle = SzLoadIds(IDS_ST_Advanced);
  364. hpsp = CreatePropertySheetPage( &psp );
  365. if (hpsp)
  366. {
  367. pWizard->RegisterPage(IDD_Advanced, hpsp,
  368. AdvancedPageCleanup, NULL);
  369. }
  370. else
  371. {
  372. hr = E_OUTOFMEMORY;
  373. }
  374. }
  375. }
  376. TraceHr(ttidWizard, FAL, hr, FALSE, "HrCreateAdvancedPage");
  377. return hr;
  378. }
  379. // ***************************************************************************
  380. // Function: AppendAdvancedPage
  381. //
  382. // Purpose: Add the Advanced page, if it was created, to the set of pages
  383. // that will be displayed.
  384. //
  385. // Parameters: pWizard [IN] - Ptr to Wizard Instance
  386. // pahpsp [IN,OUT] - Array of pages to add our page to
  387. // pcPages [IN,OUT] - Count of pages in pahpsp
  388. //
  389. // Returns: Nothing
  390. // ***************************************************************************
  391. VOID AppendAdvancedPage(CWizard *pWizard, HPROPSHEETPAGE* pahpsp, UINT *pcPages)
  392. {
  393. if (IsPostInstall(pWizard) && ( ! pWizard->FProcessLanPages()))
  394. {
  395. HPROPSHEETPAGE hPage = pWizard->GetPageHandle(IDD_Advanced);
  396. Assert(hPage);
  397. pahpsp[*pcPages] = hPage;
  398. (*pcPages)++;
  399. }
  400. }
  401. // ***************************************************************************