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.

513 lines
13 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1993 **
  4. //*********************************************************************
  5. #include "admincfg.h"
  6. extern HIMAGELIST hImageListSmall;
  7. HWND hwndUserList;
  8. CHAR gszName[MAXSTRLEN];
  9. BOOL gfMaintenance;
  10. //-----------------------------------------------------------------------
  11. // Function: AddPage(lphPages,lpwCount,id,pfn,lpsi)
  12. //
  13. // Action: Add a property sheet page to the list of pages to display.
  14. //
  15. // Return: TRUE if page was added, FALSE if not
  16. //-----------------------------------------------------------------------
  17. BOOL NEAR PASCAL AddPage(HPROPSHEETPAGE *lphPages,
  18. UINT *lpwCount,
  19. UINT id,
  20. DLGPROC pfn,
  21. HWND hwndUser)
  22. {
  23. PROPSHEETPAGE psp;
  24. memset(&psp,0,sizeof(PROPSHEETPAGE));
  25. if(NUM_WIZARD_PAGES > *lpwCount)
  26. {
  27. psp.dwSize = sizeof(psp);
  28. psp.dwFlags = PSP_DEFAULT;
  29. psp.hInstance = ghInst;
  30. psp.pszTemplate = MAKEINTRESOURCE(id);
  31. psp.pfnDlgProc = pfn;
  32. psp.lParam = (LPARAM)hwndUser;
  33. // Use release function for the first page only. This means it
  34. // always gets called exactly once if any of our pages are visited,
  35. if(!*lpwCount)
  36. {
  37. psp.dwFlags |= PSP_USECALLBACK;
  38. }
  39. lphPages[*lpwCount] = CreatePropertySheetPage(&psp);
  40. if(lphPages[*lpwCount])
  41. {
  42. (*lpwCount)++;
  43. return TRUE;
  44. }
  45. }
  46. return FALSE;
  47. }
  48. /*******************************************************************
  49. NAME: BeginEndDlgProc
  50. SYNOPSIS: Generic dialog proc for the beginning and ending wizard pages
  51. ********************************************************************/
  52. BOOL CALLBACK BeginEndDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  53. LPARAM lParam)
  54. {
  55. LPPROPSHEETPAGE lpsp;
  56. lpsp = (LPPROPSHEETPAGE)GetWindowLong(hDlg,DWL_USER);
  57. switch (uMsg) {
  58. case WM_INITDIALOG:
  59. {
  60. // get propsheet page struct passed in
  61. lpsp = (LPPROPSHEETPAGE) lParam;
  62. // store pointer to private page info in window data for later
  63. SetWindowLong(hDlg,DWL_USER,lParam);
  64. return TRUE;
  65. }
  66. break; // WM_INITDIALOG
  67. case WM_NOTIFY:
  68. {
  69. switch (((NMHDR *)lParam)->code){
  70. case PSN_SETACTIVE:
  71. // initialize 'back' and 'next' wizard buttons
  72. if (lpsp->pszTemplate == MAKEINTRESOURCE(IDD_INTRO_DLG))
  73. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT);
  74. else if (lpsp->pszTemplate == MAKEINTRESOURCE(IDD_EXPLAIN_DLG))
  75. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT | PSWIZB_BACK);
  76. else if (lpsp->pszTemplate == MAKEINTRESOURCE(IDD_END_DLG))
  77. {
  78. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_FINISH |PSWIZB_BACK);
  79. PropSheet_CancelToClose(GetParent(hDlg));
  80. }
  81. return TRUE;
  82. break;
  83. case PSN_QUERYCANCEL:
  84. SetWindowLong(hDlg,DWL_MSGRESULT,FALSE);
  85. return TRUE;
  86. break;
  87. case PSN_WIZBACK:
  88. //Finish dlg goes to different place.
  89. if (lpsp->pszTemplate == MAKEINTRESOURCE(IDD_END_DLG))
  90. {
  91. PropSheet_SetCurSel(GetParent(hDlg),NULL, I_USER_DLG);
  92. SetWindowLong(hDlg,DWL_MSGRESULT, IDD_USER_DLG);
  93. return TRUE;
  94. }
  95. }
  96. }
  97. break;
  98. }
  99. return FALSE;
  100. }
  101. /****************************************************************************\
  102. *
  103. * NAME: RestDlgProc
  104. *
  105. * SYNOPSIS: Generic dialog proc for the beginning and ending wizard pages
  106. *
  107. \****************************************************************************/
  108. BOOL CALLBACK RestDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  109. LPARAM lParam)
  110. {
  111. LPPROPSHEETPAGE lpsp;
  112. lpsp = (LPPROPSHEETPAGE)GetWindowLong(hDlg,DWL_USER);
  113. switch (uMsg) {
  114. case WM_INITDIALOG:
  115. {
  116. // get propsheet page struct passed in
  117. lpsp = (LPPROPSHEETPAGE) lParam;
  118. // store pointer to private page info in window data for later
  119. SetWindowLong(hDlg,DWL_USER,lParam);
  120. // initialize 'back' and 'next' wizard buttons, if
  121. // page wants something different it can fix in init proc below
  122. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT | PSWIZB_BACK);
  123. return TRUE;
  124. }
  125. break; // WM_INITDIALOG
  126. case WM_NOTIFY:
  127. {
  128. switch (((NMHDR *)lParam)->code){
  129. case PSN_SETACTIVE:
  130. // initialize 'back' and 'next' wizard buttons
  131. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT | PSWIZB_BACK);
  132. return TRUE;
  133. break;
  134. case PSN_QUERYCANCEL:
  135. SetWindowLong(hDlg,DWL_MSGRESULT,FALSE);
  136. return TRUE;
  137. break;
  138. }
  139. }
  140. break;
  141. }
  142. return FALSE;
  143. }
  144. /*******************************************************************
  145. NAME: MainDlgProc
  146. ********************************************************************/
  147. BOOL CALLBACK MainDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  148. LPARAM lParam)
  149. {
  150. LPPROPSHEETPAGE lpsp;
  151. USERHDR UserHdr;
  152. HGLOBAL hUser;
  153. lpsp = (LPPROPSHEETPAGE)GetWindowLong(hDlg,DWL_USER);
  154. switch (uMsg) {
  155. case WM_INITDIALOG:
  156. {
  157. // get propsheet page struct passed in
  158. lpsp = (LPPROPSHEETPAGE) lParam;
  159. // store pointer to private page info in window data for later
  160. SetWindowLong(hDlg,DWL_USER,lParam);
  161. hUser = FindUser((HWND)lpsp->lParam,gszName,UT_USER);
  162. if (!hUser || !GetUserHeader(hUser,&UserHdr)) {
  163. MsgBox(hDlg,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  164. return FALSE;
  165. }
  166. PropSheet_SetTitle(GetParent(hDlg), PSH_PROPTITLE, UserHdr.szName);
  167. // initialize 'back' and 'next' wizard buttons
  168. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT | PSWIZB_BACK);
  169. GlobalUnlock(hUser);
  170. return TRUE;
  171. }
  172. break; // WM_INITDIALOG
  173. case WM_NOTIFY:
  174. {
  175. switch (((NMHDR *)lParam)->code){
  176. case PSN_SETACTIVE:
  177. // initialize 'back' and 'next' wizard buttons
  178. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT | PSWIZB_BACK);
  179. return TRUE;
  180. break;
  181. case PSN_QUERYCANCEL:
  182. SetWindowLong(hDlg,DWL_MSGRESULT,FALSE);
  183. return TRUE;
  184. break;
  185. case PSN_WIZBACK:
  186. // In maintenance mode, Back brings you to a different screen.
  187. if (gfMaintenance)
  188. {
  189. SetWindowLong(hDlg,DWL_MSGRESULT,IDD_USER_DLG);
  190. return TRUE;
  191. }
  192. break;
  193. }
  194. }
  195. break;
  196. }
  197. return FALSE;
  198. }
  199. /****************************************************************************\
  200. *
  201. * NAME: UserDlgProc
  202. *
  203. * SYNOPSIS: Generic dialog proc for the beginning and ending wizard pages
  204. *
  205. \****************************************************************************/
  206. BOOL CALLBACK UserDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  207. LPARAM lParam)
  208. {
  209. LPPROPSHEETPAGE lpsp;
  210. USERDATA *pUserData;
  211. HGLOBAL hUser;
  212. UINT i;
  213. lpsp = (LPPROPSHEETPAGE)GetWindowLong(hDlg,DWL_USER);
  214. switch (uMsg) {
  215. case WM_INITDIALOG:
  216. {
  217. // get propsheet page struct passed in
  218. lpsp = (LPPROPSHEETPAGE) lParam;
  219. // store pointer to private page info in window data for later
  220. SetWindowLong(hDlg,DWL_USER,lParam);
  221. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_FINISH);
  222. // Once we're here, it's the same as maintenance mode.
  223. gfMaintenance = TRUE;
  224. return TRUE;
  225. }
  226. break; // WM_INITDIALOG
  227. case WM_COMMAND:
  228. switch (wParam) {
  229. case IDD_USER_ADD:
  230. //if (HIWORD(wParam) == BN_CLICK
  231. PropSheet_PressButton(GetParent(hDlg), PSBTN_NEXT);
  232. break;
  233. case IDD_USER_CHANGE:
  234. i = SendDlgItemMessage(hDlg, IDD_USER_LIST, LB_GETCURSEL, 0, 0L);
  235. if (i >= 0)
  236. {
  237. SendDlgItemMessage(hDlg, IDD_USER_LIST, LB_GETTEXT, i, (LPARAM)gszName);
  238. PropSheet_SetCurSel(GetParent(hDlg),NULL, I_MAIN_DLG);
  239. }
  240. break;
  241. }
  242. break;
  243. case WM_NOTIFY:
  244. {
  245. switch (((NMHDR *)lParam)->code){
  246. case PSN_SETACTIVE:
  247. // initialize 'back' and 'next' wizard buttons
  248. SendDlgItemMessage(hDlg, IDD_USER_LIST, LB_RESETCONTENT,0,0);
  249. i = 0;
  250. while ((hUser = (HGLOBAL) ListView_GetItemParm(hwndUser,i)) &&
  251. (pUserData = (USERDATA *) GlobalLock(hUser)))
  252. {
  253. SendDlgItemMessage(hDlg,IDD_USER_LIST, LB_ADDSTRING, 0, (LPARAM)pUserData->hdr.szName );
  254. GlobalUnlock(hUser);
  255. i++;
  256. }
  257. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_FINISH);
  258. return TRUE;
  259. break;
  260. case PSN_QUERYCANCEL:
  261. SetWindowLong(hDlg,DWL_MSGRESULT,FALSE);
  262. return TRUE;
  263. break;
  264. case PSN_WIZFINISH:
  265. // save changes if user OK's the dialog
  266. dwAppState = AS_FILELOADED | AS_FILEHASNAME | AS_POLICYFILE | AS_FILEDIRTY;
  267. if (!SaveFile(szDatFilename,hDlg,(HWND)lpsp->lParam))
  268. dwDlgRetCode = AD_POLSAVEERR;
  269. PropSheet_SetCurSel(GetParent(hDlg),NULL, I_END_DLG);
  270. SetWindowLong(hDlg,DWL_MSGRESULT,IDD_END_DLG);
  271. return TRUE;
  272. break;
  273. }
  274. }
  275. break;
  276. }
  277. return FALSE;
  278. }
  279. /*******************************************************************
  280. NAME: NewUserDlgProc
  281. ********************************************************************/
  282. BOOL CALLBACK NewUserDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
  283. LPARAM lParam)
  284. {
  285. LPPROPSHEETPAGE lpsp;
  286. HGLOBAL hUser;
  287. UINT nRet;
  288. CHAR szName[MAXSTRLEN];
  289. lpsp = (LPPROPSHEETPAGE)GetWindowLong(hDlg,DWL_USER);
  290. switch (uMsg) {
  291. case WM_INITDIALOG:
  292. {
  293. // get propsheet page struct passed in
  294. lpsp = (LPPROPSHEETPAGE) lParam;
  295. // store pointer to private page info in window data for later
  296. SetWindowLong(hDlg,DWL_USER,lParam);
  297. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT | PSWIZB_BACK);
  298. return TRUE;
  299. }
  300. break; // WM_INITDIALOG
  301. case WM_NOTIFY:
  302. {
  303. switch (((NMHDR *)lParam)->code){
  304. case PSN_WIZNEXT:
  305. if (!GetDlgItemText(hDlg, IDD_NEWUSER_NAME, szName, sizeof(szName)))
  306. {
  307. MsgBox(hDlg, IDS_NOUSER, MB_ICONEXCLAMATION,MB_OK);
  308. SetWindowLong(hDlg,DWL_MSGRESULT, -1);
  309. return TRUE;
  310. }
  311. hUser = FindUser(hwndUser,szName, UT_USER);
  312. if ((hUser) &&
  313. (MsgBox(hDlg, IDS_USEREXISTS, MB_ICONEXCLAMATION, MB_YESNO) != IDYES))
  314. {
  315. // Allow user to enter another name.
  316. SetWindowLong(hDlg,DWL_MSGRESULT,-1);
  317. return TRUE;
  318. }
  319. if (!hUser) {
  320. hUser = AddUser(hwndUser,szName,UT_USER);
  321. }
  322. if (!hUser) {
  323. MsgBox(hDlg,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  324. dwDlgRetCode = AD_OUTOFMEMORY;
  325. return FALSE;
  326. }
  327. GlobalUnlock(hUser);
  328. lstrcpy(szName, gszName);
  329. SetWindowLong(hDlg,DWL_MSGRESULT, IDD_MAIN_DLG);
  330. return TRUE;
  331. break;
  332. case PSN_SETACTIVE:
  333. // initialize 'back' and 'next' wizard buttons
  334. PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_NEXT | PSWIZB_BACK);
  335. return TRUE;
  336. break;
  337. case PSN_QUERYCANCEL:
  338. SetWindowLong(hDlg,DWL_MSGRESULT,FALSE);
  339. return TRUE;
  340. break;
  341. }
  342. }
  343. break;
  344. }
  345. return FALSE;
  346. }
  347. BOOL WINAPI DoWizard(HWND hWnd, HWND hwndUser)
  348. {
  349. HPROPSHEETPAGE hPages[NUM_WIZARD_PAGES];
  350. PROPSHEETHEADER psHeader;
  351. int iRet;
  352. // zero out structures
  353. memset(&hPages,0,sizeof(hPages));
  354. memset(&psHeader,0,sizeof(psHeader));
  355. AddPage((HPROPSHEETPAGE *)&hPages, &psHeader.nPages, IDD_INTRO_DLG, BeginEndDlgProc, hwndUser);
  356. AddPage((HPROPSHEETPAGE *)&hPages, &psHeader.nPages, IDD_EXPLAIN_DLG, BeginEndDlgProc, hwndUser);
  357. AddPage((HPROPSHEETPAGE *)&hPages, &psHeader.nPages, IDD_MAIN_DLG, MainDlgProc, hwndUser);
  358. AddPage((HPROPSHEETPAGE *)&hPages, &psHeader.nPages, IDD_UNRATE_DLG, RestDlgProc, hwndUser);
  359. AddPage((HPROPSHEETPAGE *)&hPages, &psHeader.nPages, IDD_USER_DLG, UserDlgProc, hwndUser);
  360. AddPage((HPROPSHEETPAGE *)&hPages, &psHeader.nPages, IDD_NEWUSER_DLG, NewUserDlgProc, hwndUser);
  361. AddPage((HPROPSHEETPAGE *)&hPages, &psHeader.nPages, IDD_END_DLG, BeginEndDlgProc, hwndUser);
  362. // fill out property sheet header struct
  363. psHeader.dwSize = sizeof(psHeader);
  364. psHeader.dwFlags = PSH_WIZARD;
  365. psHeader.hwndParent = hWnd;
  366. psHeader.hInstance = ghInst;
  367. psHeader.phpage = hPages;
  368. // Set global information
  369. LoadSz(IDS_DEFAULTUSER,gszName,sizeof(gszName));
  370. gfMaintenance = FALSE;
  371. // run the Wizard
  372. iRet = PropertySheet(&psHeader);
  373. if (iRet < 0) {
  374. // property sheet failed, most likely due to lack of memory
  375. MsgBox(NULL,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  376. }
  377. return (iRet > 0);
  378. }