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.

416 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ListCtrl.cpp
  5. Abstract:
  6. Functions for "Welcome" and "Finish" pages of the wizard.
  7. Author:
  8. Sergey Kuzin (a-skuzin@microsoft.com) 09-August-1999
  9. Environment:
  10. Revision History:
  11. --*/
  12. #include "tsverui.h"
  13. #include "resource.h"
  14. void OnFinish(HWND hwndDlg, LPSHAREDWIZDATA pdata);
  15. void ShowErrorBox(HWND hwndDlg, DWORD dwError);
  16. /*++
  17. Routine Description :
  18. dialog box procedure for the "Welcome" page.
  19. Arguments :
  20. IN HWND hwndDlg - handle to dialog box.
  21. IN UINT uMsg - message to be acted upon.
  22. IN WPARAM wParam - value specific to wMsg.
  23. IN LPARAM lParam - value specific to wMsg.
  24. Return Value :
  25. TRUE if it processed the message
  26. FALSE if it did not.
  27. --*/
  28. INT_PTR CALLBACK
  29. StartPageProc (
  30. HWND hwndDlg,
  31. UINT uMsg,
  32. WPARAM wParam,
  33. LPARAM lParam
  34. )
  35. {
  36. //Process messages from the Welcome page
  37. //Retrieve the shared user data from GWL_USERDATA
  38. LPSHAREDWIZDATA pdata = (LPSHAREDWIZDATA) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  39. switch (uMsg)
  40. {
  41. case WM_INITDIALOG :
  42. {
  43. //Get the shared data from PROPSHEETPAGE lParam value
  44. //and load it into GWL_USERDATA
  45. pdata = (LPSHAREDWIZDATA) ((LPPROPSHEETPAGE) lParam) -> lParam;
  46. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR) pdata);
  47. //It's an intro/end page, so get the title font
  48. //from the shared data and use it for the title control
  49. HWND hwndControl = GetDlgItem(hwndDlg, IDC_TITLE);
  50. SetWindowFont(hwndControl,pdata->hTitleFont, TRUE);
  51. break;
  52. }
  53. case WM_NOTIFY :
  54. {
  55. LPNMHDR lpnm = (LPNMHDR) lParam;
  56. switch (lpnm->code)
  57. {
  58. case PSN_SETACTIVE : //Enable the Next button
  59. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
  60. break;
  61. case PSN_WIZNEXT :
  62. //Handle a Next button click here
  63. if(IsDlgButtonChecked(hwndDlg,IDC_NOWELLCOME)==BST_CHECKED){
  64. pdata->bNoWellcome=TRUE;
  65. }
  66. break;
  67. case PSN_RESET :
  68. //Handle a Cancel button click, if necessary
  69. break;
  70. default :
  71. break;
  72. }
  73. }
  74. break;
  75. default:
  76. break;
  77. }
  78. return 0;
  79. }
  80. /*++
  81. Routine Description :
  82. dialog box procedure for the "Finish" page.
  83. Arguments :
  84. IN HWND hwndDlg - handle to dialog box.
  85. IN UINT uMsg - message to be acted upon.
  86. IN WPARAM wParam - value specific to wMsg.
  87. IN LPARAM lParam - value specific to wMsg.
  88. Return Value :
  89. TRUE if it processed the message
  90. FALSE if it did not.
  91. --*/
  92. INT_PTR CALLBACK FinishPageProc (
  93. HWND hwndDlg,
  94. UINT uMsg,
  95. WPARAM wParam,
  96. LPARAM lParam
  97. )
  98. {
  99. //Process messages from the Completion page
  100. //Retrieve the shared user data from GWL_USERDATA
  101. LPSHAREDWIZDATA pdata = (LPSHAREDWIZDATA) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  102. switch (uMsg)
  103. {
  104. case WM_INITDIALOG :
  105. {
  106. //Get the shared data from PROPSHEETPAGE lParam value
  107. //and load it into GWL_USERDATA
  108. pdata = (LPSHAREDWIZDATA) ((LPPROPSHEETPAGE) lParam) -> lParam;
  109. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR) pdata);
  110. //It's an intro/end page, so get the title font
  111. //from userdata and use it on the title control
  112. HWND hwndControl = GetDlgItem(hwndDlg, IDC_TITLE);
  113. SetWindowFont(hwndControl,pdata->hTitleFont, TRUE);
  114. break;
  115. }
  116. case WM_NOTIFY :
  117. {
  118. LPNMHDR lpnm = (LPNMHDR) lParam;
  119. switch (lpnm->code)
  120. {
  121. case PSN_SETACTIVE : //Enable the correct buttons on for the active page
  122. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
  123. break;
  124. case PSN_WIZBACK :
  125. //If the checkbox was checked, jump back
  126. //to the first interior page, not the second
  127. if(!pdata->bCheckingEnabled)
  128. {
  129. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_VERSION_CHECKING);
  130. return TRUE;
  131. }
  132. break;
  133. case PSN_WIZFINISH :
  134. //Handle a Finish button click, if necessary
  135. OnFinish(hwndDlg,pdata);
  136. break;
  137. case PSN_RESET :
  138. //Handle a Cancel button click, if necessary
  139. break;
  140. default :
  141. break;
  142. }
  143. }
  144. break;
  145. default:
  146. break;
  147. }
  148. return 0;
  149. }
  150. /*++
  151. Routine Description :
  152. writes all data into the registry.
  153. Arguments :
  154. IN HWND hwndDlg - handle to dialog box.
  155. IN LPSHAREDWIZDATA pdata - pointer to the data struct.
  156. Return Value :
  157. none
  158. --*/
  159. void
  160. OnFinish(
  161. HWND hwndDlg,
  162. LPSHAREDWIZDATA pdata)
  163. {
  164. LONG lResult;
  165. //
  166. if(pdata->bNoWellcome){
  167. lResult=SetRegKey(HKEY_USERS, szConstraintsKeyPath,
  168. KeyName[NOWELLCOME], 1);
  169. if(lResult!=ERROR_SUCCESS){
  170. ShowErrorBox(hwndDlg,lResult);
  171. return;
  172. }
  173. }
  174. //
  175. if (pdata->bCheckingEnabled){
  176. lResult=SetRegKey(HKEY_LOCAL_MACHINE, szKeyPath,
  177. KeyName[ASYNCHRONOUS], 0);
  178. if(lResult!=ERROR_SUCCESS){
  179. ShowErrorBox(hwndDlg,lResult);
  180. return;
  181. }
  182. lResult=SetRegKey(HKEY_LOCAL_MACHINE, szKeyPath,
  183. KeyName[IMPERSONATE], 0);
  184. if(lResult!=ERROR_SUCCESS){
  185. ShowErrorBox(hwndDlg,lResult);
  186. return;
  187. }
  188. lResult=SetRegKeyString(HKEY_LOCAL_MACHINE,
  189. TEXT("tsver.dll"),szKeyPath, KeyName[DLLNAME]);
  190. if(lResult!=ERROR_SUCCESS){
  191. ShowErrorBox(hwndDlg,lResult);
  192. return;
  193. }
  194. lResult=SetRegKeyString(HKEY_LOCAL_MACHINE,
  195. TEXT("TsVerEventStartup"), szKeyPath, KeyName[STARTUP]);
  196. if(lResult!=ERROR_SUCCESS){
  197. ShowErrorBox(hwndDlg,lResult);
  198. return;
  199. }
  200. } else { // delete all the keys
  201. for (int i = 0; i < 4; i++){
  202. lResult=DeleteRegKey(HKEY_LOCAL_MACHINE, szKeyPath, KeyName[i]);
  203. if(lResult!=ERROR_SUCCESS){
  204. ShowErrorBox(hwndDlg,lResult);
  205. return;
  206. }
  207. }
  208. //do not save other members, they are not valid!
  209. return;
  210. }
  211. //write message
  212. if (pdata->bMessageEnabled)
  213. {
  214. lResult=SetRegKey(HKEY_USERS, szConstraintsKeyPath, KeyName[USE_MSG], 1);
  215. if(lResult!=ERROR_SUCCESS){
  216. ShowErrorBox(hwndDlg,lResult);
  217. return;
  218. }
  219. } else {
  220. lResult=DeleteRegKey(HKEY_USERS, szConstraintsKeyPath, KeyName[USE_MSG]);
  221. if(lResult!=ERROR_SUCCESS){
  222. ShowErrorBox(hwndDlg,lResult);
  223. return;
  224. }
  225. }
  226. // write constraints string
  227. if (pdata->pszConstraints&&_tcslen(pdata->pszConstraints)){
  228. lResult=SetRegKeyString(HKEY_USERS, pdata->pszConstraints,
  229. szConstraintsKeyPath,
  230. KeyName[CONSTRAINTS]);
  231. if(lResult!=ERROR_SUCCESS){
  232. ShowErrorBox(hwndDlg,lResult);
  233. return;
  234. }
  235. } else {
  236. lResult=DeleteRegKey(HKEY_USERS,
  237. szConstraintsKeyPath,
  238. KeyName[CONSTRAINTS]);
  239. if(lResult!=ERROR_SUCCESS){
  240. ShowErrorBox(hwndDlg,lResult);
  241. return;
  242. }
  243. }
  244. // write title string
  245. if (pdata->pszMessageTitle&&_tcslen(pdata->pszMessageTitle)){
  246. lResult=SetRegKeyString(HKEY_USERS, pdata->pszMessageTitle,
  247. szConstraintsKeyPath,
  248. KeyName[MSG_TITLE]);
  249. if(lResult!=ERROR_SUCCESS){
  250. ShowErrorBox(hwndDlg,lResult);
  251. return;
  252. }
  253. } else {
  254. lResult=DeleteRegKey(HKEY_USERS,
  255. szConstraintsKeyPath,
  256. KeyName[MSG_TITLE]);
  257. if(lResult!=ERROR_SUCCESS){
  258. ShowErrorBox(hwndDlg,lResult);
  259. return;
  260. }
  261. }
  262. // write message string
  263. if (pdata->pszMessageText&&_tcslen(pdata->pszMessageText)){
  264. lResult=SetRegKeyString(HKEY_USERS, pdata->pszMessageText,
  265. szConstraintsKeyPath,
  266. KeyName[MSG]);
  267. if(lResult!=ERROR_SUCCESS){
  268. ShowErrorBox(hwndDlg,lResult);
  269. return;
  270. }
  271. } else {
  272. lResult=DeleteRegKey(HKEY_USERS,
  273. szConstraintsKeyPath,
  274. KeyName[MSG]);
  275. if(lResult!=ERROR_SUCCESS){
  276. ShowErrorBox(hwndDlg,lResult);
  277. return;
  278. }
  279. }
  280. }
  281. /*++
  282. Routine Description :
  283. shows MessageBox with error message.
  284. Arguments :
  285. IN HWND hwndDlg - handle to dialog box.
  286. IN DWORD dwError - error code.
  287. Return Value :
  288. none
  289. --*/
  290. void
  291. ShowErrorBox(
  292. HWND hwndDlg,
  293. DWORD dwError)
  294. {
  295. LPTSTR MsgBuf=NULL;
  296. DWORD dwFlags=FORMAT_MESSAGE_FROM_SYSTEM|
  297. FORMAT_MESSAGE_ALLOCATE_BUFFER|
  298. FORMAT_MESSAGE_IGNORE_INSERTS;
  299. if(!FormatMessage(
  300. dwFlags,
  301. NULL, dwError,
  302. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  303. (LPTSTR)&MsgBuf, 0, NULL )){
  304. MsgBuf=(LPTSTR)LocalAlloc(LPTR,2*sizeof(TCHAR));
  305. if(MsgBuf == NULL) {
  306. return;
  307. }
  308. MsgBuf[0]=' ';
  309. }
  310. TCHAR szTemplate[256];
  311. LoadString(g_hInst,IDS_SAVE_ERROR,szTemplate,255);
  312. LPTSTR szErrorMsg=new TCHAR[_tcslen(MsgBuf)+_tcslen(szTemplate)+1];
  313. if(szErrorMsg == NULL) {
  314. return;
  315. }
  316. wsprintf(szErrorMsg,szTemplate,MsgBuf);
  317. MessageBox(hwndDlg,szErrorMsg,NULL,MB_OK|MB_ICONERROR);
  318. delete szErrorMsg;
  319. LocalFree(MsgBuf);
  320. }