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.

504 lines
11 KiB

  1. //+------------------------------------------------------------------
  2. //
  3. // Project: Windows NT4 DS Client Setup Wizard
  4. //
  5. // Purpose: Installs the Windows NT4 DS Client Files
  6. //
  7. // File: wizard.cpp
  8. //
  9. // History: March 1998 Zeyong Xu Created
  10. // Jan 2000 Jeff Jones (JeffJon) Modified
  11. // - changed to be an NT setup
  12. //
  13. //------------------------------------------------------------------
  14. #include <windows.h>
  15. #include <windowsx.h>
  16. #include <prsht.h>
  17. #include "resource.h"
  18. #include "dscsetup.h"
  19. #include "doinst.h"
  20. #include "wizard.h"
  21. extern SInstallVariables g_sInstVar;
  22. // welcome page DlgProc of wizard
  23. BOOL CALLBACK WelcomeDialogProc(HWND hWnd,
  24. UINT nMessage,
  25. WPARAM wParam,
  26. LPARAM lParam)
  27. {
  28. BOOL bReturn = FALSE;
  29. LPNMHDR lpNotifyMsg;
  30. switch (nMessage)
  31. {
  32. case WM_INITDIALOG:
  33. {
  34. RECT rc;
  35. // set font of title text
  36. SetWindowFont(GetDlgItem(hWnd, IDC_STATIC_WELCOME_TITLE),
  37. g_sInstVar.m_hBigBoldFont,
  38. TRUE);
  39. // Position the dialog
  40. if (GetWindowRect(GetParent(hWnd), &rc))
  41. {
  42. SetWindowPos(GetParent(hWnd),
  43. HWND_TOP,
  44. (GetSystemMetrics(SM_CXSCREEN) / 2) -
  45. ((rc.right - rc.left) / 2),
  46. (GetSystemMetrics(SM_CYSCREEN) / 2) -
  47. ((rc.bottom - rc.top) / 2),
  48. rc.right - rc.left,
  49. rc.bottom - rc.top,
  50. SWP_NOOWNERZORDER);
  51. }
  52. break;
  53. }
  54. case WM_NOTIFY:
  55. lpNotifyMsg = (NMHDR FAR*) lParam;
  56. switch (lpNotifyMsg->code)
  57. {
  58. // user click cancel
  59. case PSN_QUERYCANCEL:
  60. // cancel confirm?
  61. if(!ConfirmCancelWizard(hWnd))
  62. {
  63. SetWindowLongPtr(hWnd, DWL_MSGRESULT, TRUE);
  64. bReturn = TRUE;
  65. }
  66. break;
  67. case PSN_WIZNEXT:
  68. break;
  69. case PSN_SETACTIVE:
  70. PropSheet_SetWizButtons(GetParent(hWnd), PSWIZB_NEXT);
  71. break;
  72. default:
  73. break;
  74. }
  75. break;
  76. default:
  77. break;
  78. }
  79. return bReturn;
  80. }
  81. /* ntbug#337931: remove license page
  82. // License page DlgProc of wizard
  83. BOOL CALLBACK LicenseDialogProc(HWND hWnd,
  84. UINT nMessage,
  85. WPARAM wParam,
  86. LPARAM lParam)
  87. {
  88. BOOL bReturn = FALSE;
  89. LPNMHDR lpNotifyMsg;
  90. HFONT hLicenseTextFont;
  91. switch (nMessage)
  92. {
  93. case WM_INITDIALOG:
  94. if(!CheckDiskSpace() || // check disk space
  95. !LoadLicenseFile(hWnd)) // Load license file
  96. {
  97. g_sInstVar.m_nSetupResult = SETUP_ERROR;
  98. PropSheet_PressButton(GetParent(hWnd), PSBTN_FINISH); // close wizard
  99. }
  100. // use a ANSI_FIXED_FONT (Couirer) font for EULA to replace the default
  101. // font - MS Shell Dlg in order to fix the bug in Hebrew Win95
  102. if(g_sInstVar.m_bWin95)
  103. {
  104. hLicenseTextFont = (HFONT) GetStockObject(ANSI_FIXED_FONT);
  105. if(hLicenseTextFont)
  106. {
  107. SetWindowFont(GetDlgItem(hWnd, IDC_LICENSE_TEXT),
  108. hLicenseTextFont,
  109. TRUE);
  110. }
  111. }
  112. bReturn = TRUE;
  113. break;
  114. case WM_NOTIFY:
  115. lpNotifyMsg = (NMHDR FAR*) lParam;
  116. switch (lpNotifyMsg->code)
  117. {
  118. // user click cancel
  119. case PSN_QUERYCANCEL:
  120. // cancel confirm?
  121. if(!ConfirmCancelWizard(hWnd))
  122. {
  123. SetWindowLongPtr(hWnd, DWL_MSGRESULT, TRUE);
  124. bReturn = TRUE;
  125. }
  126. break;
  127. case PSN_WIZNEXT:
  128. break;
  129. case PSN_SETACTIVE:
  130. {
  131. HWND hButton;
  132. hButton = GetDlgItem(hWnd, IDC_RADIO_ACCEPTED);
  133. // get radio button check status
  134. if( hButton &&
  135. BST_CHECKED == SendMessage(hButton, BM_GETCHECK, 0, 0L) )
  136. PropSheet_SetWizButtons(GetParent(hWnd),
  137. PSWIZB_BACK | PSWIZB_NEXT);
  138. else
  139. PropSheet_SetWizButtons(GetParent(hWnd),
  140. PSWIZB_BACK);
  141. break;
  142. }
  143. default:
  144. break;
  145. }
  146. break;
  147. case WM_COMMAND: // button click
  148. {
  149. HWND hButton;
  150. hButton = GetDlgItem(hWnd, IDC_RADIO_ACCEPTED);
  151. // get radio button check status
  152. if( hButton && BST_CHECKED ==
  153. SendMessage(hButton, BM_GETCHECK, 0, 0L) )
  154. PropSheet_SetWizButtons(GetParent(hWnd),
  155. PSWIZB_BACK | PSWIZB_NEXT);
  156. else
  157. PropSheet_SetWizButtons(GetParent(hWnd),
  158. PSWIZB_BACK);
  159. }
  160. default:
  161. break;
  162. }
  163. return bReturn;
  164. }
  165. */
  166. // Confirm page DlgProc of wizard
  167. BOOL CALLBACK ConfirmDialogProc(HWND hWnd,
  168. UINT nMessage,
  169. WPARAM wParam,
  170. LPARAM lParam)
  171. {
  172. BOOL bReturn = FALSE;
  173. LPNMHDR lpNotifyMsg;
  174. switch (nMessage)
  175. {
  176. case WM_INITDIALOG:
  177. if(!CheckDiskSpace()) // check disk space
  178. {
  179. g_sInstVar.m_nSetupResult = SETUP_ERROR;
  180. PropSheet_PressButton(GetParent(hWnd), PSBTN_FINISH); // close wizard
  181. }
  182. // check if DSClient has been installed
  183. if(CheckDSClientInstalled())
  184. {
  185. // load string and dispaly it in textitem
  186. TCHAR szMessage[MAX_MESSAGE + 1];
  187. LoadString(g_sInstVar.m_hInstance,
  188. IDS_REINSTALL_MSG,
  189. szMessage,
  190. MAX_MESSAGE);
  191. SetDlgItemText(hWnd,
  192. IDC_STATIC_CONFIRM_INSTALL,
  193. szMessage);
  194. }
  195. break;
  196. case WM_NOTIFY:
  197. lpNotifyMsg = (NMHDR FAR*) lParam;
  198. switch (lpNotifyMsg->code)
  199. {
  200. // user click cancel
  201. case PSN_QUERYCANCEL:
  202. // cancel confirm?
  203. if(!ConfirmCancelWizard(hWnd))
  204. {
  205. SetWindowLongPtr(hWnd, DWL_MSGRESULT, TRUE);
  206. bReturn = TRUE;
  207. }
  208. break;
  209. case PSN_WIZNEXT:
  210. break;
  211. case PSN_SETACTIVE:
  212. PropSheet_SetWizButtons(GetParent(hWnd),
  213. PSWIZB_BACK | PSWIZB_NEXT);
  214. break;
  215. default:
  216. break;
  217. }
  218. break;
  219. default:
  220. break;
  221. }
  222. return bReturn;
  223. }
  224. // wizard dialog callback function
  225. BOOL CALLBACK InstallDialogProc(HWND hWnd,
  226. UINT nMessage,
  227. WPARAM wParam,
  228. LPARAM lParam)
  229. {
  230. BOOL bReturn = FALSE;
  231. LPNMHDR lpMsg;
  232. switch (nMessage)
  233. {
  234. case WM_INITDIALOG:
  235. {
  236. DWORD dwThreadId;
  237. // get the handle of install progress bar and file name item
  238. g_sInstVar.m_hProgress = GetDlgItem(hWnd, IDC_INSTALL_PROGRESS);
  239. g_sInstVar.m_hFileNameItem = GetDlgItem(hWnd, IDC_STATIC_FILENAME);
  240. // start to do installation
  241. g_sInstVar.m_hInstallThread = CreateThread(NULL,
  242. 0,
  243. DoInstallationProc,
  244. hWnd,
  245. 0,
  246. &dwThreadId);
  247. // if CreateThread() failed
  248. if(!g_sInstVar.m_hInstallThread)
  249. {
  250. g_sInstVar.m_nSetupResult = SETUP_ERROR;
  251. PropSheet_PressButton(GetParent(hWnd), PSBTN_FINISH); // close wizard
  252. }
  253. bReturn = TRUE;
  254. break;
  255. }
  256. case WM_NOTIFY:
  257. {
  258. lpMsg = (NMHDR FAR*) lParam;
  259. switch(lpMsg->code)
  260. {
  261. // cancel to do nothing
  262. case PSN_QUERYCANCEL:
  263. // block
  264. EnterCriticalSection(&g_sInstVar.m_oCriticalSection);
  265. // cancel confirm?
  266. if(!ConfirmCancelWizard(hWnd))
  267. {
  268. SetWindowLongPtr(hWnd, DWL_MSGRESULT, TRUE);
  269. bReturn = TRUE;
  270. }
  271. // unblock
  272. LeaveCriticalSection(&g_sInstVar.m_oCriticalSection);
  273. break;
  274. case PSN_WIZFINISH:
  275. break;
  276. case PSN_WIZBACK:
  277. break;
  278. case PSN_SETACTIVE:
  279. PropSheet_SetWizButtons(GetParent(hWnd), 0);
  280. break;
  281. default:
  282. break;
  283. }
  284. }
  285. default:
  286. break;
  287. }
  288. return bReturn;
  289. }
  290. // Completion page DlgProc of wizard
  291. BOOL CALLBACK CompletionDialogProc(HWND hWnd,
  292. UINT nMessage,
  293. WPARAM wParam,
  294. LPARAM lParam)
  295. {
  296. BOOL bReturn = FALSE;
  297. LPNMHDR lpNotifyMsg;
  298. switch (nMessage)
  299. {
  300. case WM_INITDIALOG:
  301. {
  302. TCHAR szMessage[MAX_MESSAGE + 1];
  303. RECT rc;
  304. // load string and dispaly it in textitem
  305. switch (g_sInstVar.m_nSetupResult)
  306. {
  307. case SETUP_SUCCESS:
  308. LoadString(g_sInstVar.m_hInstance,
  309. IDS_SETUP_SUCCESS_TITLE,
  310. szMessage,
  311. MAX_MESSAGE);
  312. SetDlgItemText(hWnd, IDC_STATIC_COMPLETION_TITLE, szMessage);
  313. LoadString(g_sInstVar.m_hInstance,
  314. IDS_SETUP_SUCCESS,
  315. szMessage,
  316. MAX_MESSAGE);
  317. SetDlgItemText(hWnd, IDC_STATIC_COMPLETION, szMessage);
  318. break;
  319. case SETUP_CANCEL:
  320. LoadString(g_sInstVar.m_hInstance,
  321. IDS_SETUP_CANCEL_TITLE,
  322. szMessage,
  323. MAX_MESSAGE);
  324. SetDlgItemText(hWnd, IDC_STATIC_COMPLETION_TITLE, szMessage);
  325. LoadString(g_sInstVar.m_hInstance,
  326. IDS_SETUP_CANCEL,
  327. szMessage,
  328. MAX_MESSAGE);
  329. SetDlgItemText(hWnd, IDC_STATIC_COMPLETION, szMessage);
  330. break;
  331. case SETUP_ERROR:
  332. LoadString(g_sInstVar.m_hInstance,
  333. IDS_SETUP_ERROR_TITLE,
  334. szMessage,
  335. MAX_MESSAGE);
  336. SetDlgItemText(hWnd, IDC_STATIC_COMPLETION_TITLE, szMessage);
  337. LoadString(g_sInstVar.m_hInstance,
  338. IDS_SETUP_ERROR,
  339. szMessage,
  340. MAX_MESSAGE);
  341. SetDlgItemText(hWnd, IDC_STATIC_COMPLETION, szMessage);
  342. break;
  343. default:
  344. break;
  345. }
  346. // set font of title text
  347. SetWindowFont(GetDlgItem(hWnd, IDC_STATIC_COMPLETION_TITLE),
  348. g_sInstVar.m_hBigBoldFont,
  349. TRUE);
  350. // Position the dialog
  351. if (GetWindowRect(GetParent(hWnd), &rc))
  352. {
  353. SetWindowPos(GetParent(hWnd),
  354. HWND_TOP,
  355. (GetSystemMetrics(SM_CXSCREEN) / 2) -
  356. ((rc.right - rc.left) / 2),
  357. (GetSystemMetrics(SM_CYSCREEN) / 2) -
  358. ((rc.bottom - rc.top) / 2),
  359. rc.right - rc.left,
  360. rc.bottom - rc.top,
  361. SWP_NOOWNERZORDER);
  362. }
  363. break;
  364. }
  365. case WM_NOTIFY:
  366. lpNotifyMsg = (NMHDR FAR*) lParam;
  367. switch (lpNotifyMsg->code)
  368. {
  369. case PSN_QUERYCANCEL:
  370. break;
  371. case PSN_WIZFINISH:
  372. break;
  373. case PSN_SETACTIVE:
  374. // set wizard button
  375. PropSheet_SetWizButtons(GetParent(hWnd), PSWIZB_FINISH);
  376. PropSheet_CancelToClose(GetParent(hWnd));
  377. break;
  378. default:
  379. break;
  380. }
  381. break;
  382. default:
  383. break;
  384. }
  385. return bReturn;
  386. }
  387. // ask if you want to cancel the wizard
  388. BOOL ConfirmCancelWizard(HWND hWnd)
  389. {
  390. TCHAR szMsg[MAX_MESSAGE + 1];
  391. TCHAR szTitle[MAX_TITLE + 1];
  392. LoadString(g_sInstVar.m_hInstance, IDS_CANCEL_TITLE, szTitle, MAX_TITLE);
  393. LoadString(g_sInstVar.m_hInstance, IDS_CANCEL_MSG, szMsg, MAX_MESSAGE);
  394. if (IDYES == MessageBox(hWnd,
  395. szMsg,
  396. szTitle,
  397. MB_YESNO | MB_TOPMOST | MB_ICONQUESTION))
  398. {
  399. // kill timer
  400. if(g_sInstVar.m_uTimerID)
  401. KillTimer(hWnd, g_sInstVar.m_uTimerID);
  402. // set m_nSetupResult to SETUP_CANCEL, in order to stop the inatllation
  403. g_sInstVar.m_nSetupResult = SETUP_CANCEL;
  404. return TRUE;
  405. }
  406. return FALSE;
  407. }
  408. // do installation proc
  409. DWORD WINAPI DoInstallationProc(LPVOID lpVoid)
  410. {
  411. HWND hWnd = (HWND)lpVoid;
  412. // do installation
  413. g_sInstVar.m_nSetupResult = DoInstallation(hWnd);
  414. // Close install page of the setup wizard
  415. PropSheet_PressButton(GetParent(hWnd), PSBTN_FINISH);
  416. return g_sInstVar.m_nSetupResult;
  417. }