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.

343 lines
12 KiB

  1. /****************************************************************************\
  2. SCREENS2.C / OPK Wizard (OPKWIZ.EXE)
  3. Microsoft Confidential
  4. Copyright (c) Microsoft Corporation 1998
  5. All rights reserved
  6. Source file for the OPK Wizard that contains the external and internal
  7. functions used by the "screenstwo" wizard page.
  8. 10/99 - Stephen Lodwick (A-STELO)
  9. Added this page
  10. 09/2000 - Stephen Lodwick (STELO)
  11. Ported OPK Wizard to Whistler
  12. \****************************************************************************/
  13. //
  14. // Include File(s):
  15. //
  16. #include "pch.h"
  17. #include "wizard.h"
  18. #include "resource.h"
  19. #include "screens2.h"
  20. //
  21. // Internal Defined Value(s):
  22. //
  23. #define INI_KEY_REGIONAL _T("INTL_Settings")
  24. #define INI_KEY_TIMEZONE _T("TimeZone")
  25. #define INI_KEY_TIMEZONEVALUE _T("TimeZoneValue")
  26. #define INI_SEC_TIMEZONES _T("TimeZones")
  27. #define INI_KEY_DEFAULTLOCALE _T("DefaultLanguage")
  28. #define INI_SEC_LOCALE _T("Languages")
  29. #define INI_KEY_DEFAULTREGION _T("DefaultRegion")
  30. #define INI_SEC_REGION _T("Regions")
  31. #define INI_KEY_DEFAULTKEYBD _T("DefaultKeyboard")
  32. #define INI_SEC_KEYBD _T("Keyboards")
  33. //
  34. // Internal Structure(s):
  35. //
  36. typedef struct _OOBEOPTIONS
  37. {
  38. INT ListBox;
  39. LPTSTR lpDefaultKey;
  40. LPTSTR lpAlternateSection;
  41. LPTSTR lpOutputFormat;
  42. LPLONGRES lplrListItems;
  43. INT dwListSize;
  44. } OOBEOPTIONS, *LPOOBEOPTIONS;
  45. //
  46. // Global Define(s):
  47. //
  48. static OOBEOPTIONS g_OobeOptions [] =
  49. {
  50. { IDC_TIMEZONE, INI_KEY_TIMEZONEVALUE, INI_SEC_TIMEZONES, _T("%03lu"), lr_timezone_default, AS(lr_timezone_default) },
  51. { IDC_LOCALE, INI_KEY_DEFAULTLOCALE, INI_SEC_LOCALE, _T("%x"), lr_location_default, AS(lr_location_default) },
  52. { IDC_REGION, INI_KEY_DEFAULTREGION, INI_SEC_REGION, _T("%d"), lr_region_default, AS(lr_region_default) },
  53. { IDC_KEYBOARD, INI_KEY_DEFAULTKEYBD, INI_SEC_KEYBD, _T("%x"), lr_keyboard_default, AS(lr_keyboard_default) },
  54. };
  55. //
  56. // Internal Function Prototype(s):
  57. //
  58. static BOOL OnInit(HWND, HWND, LPARAM);
  59. static void OnNext(HWND);
  60. static void LoadListBox(HWND, OOBEOPTIONS);
  61. //
  62. // External Function(s):
  63. //
  64. LRESULT CALLBACK ScreensTwoDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  65. {
  66. switch (uMsg)
  67. {
  68. HANDLE_MSG(hwnd, WM_INITDIALOG, OnInit);
  69. case WM_NOTIFY:
  70. switch ( ((NMHDR FAR *) lParam)->code )
  71. {
  72. case PSN_KILLACTIVE:
  73. case PSN_RESET:
  74. case PSN_WIZBACK:
  75. case PSN_WIZFINISH:
  76. break;
  77. case PSN_WIZNEXT:
  78. OnNext(hwnd);
  79. break;
  80. case PSN_QUERYCANCEL:
  81. WIZ_CANCEL(hwnd);
  82. break;
  83. case PSN_SETACTIVE:
  84. g_App.dwCurrentHelp = IDH_SCREENSTWO;
  85. WIZ_BUTTONS(hwnd, PSWIZB_BACK | PSWIZB_NEXT);
  86. // Press next if the user is in auto mode
  87. //
  88. WIZ_NEXTONAUTO(hwnd, PSBTN_NEXT);
  89. break;
  90. case PSN_HELP:
  91. WIZ_HELP();
  92. break;
  93. default:
  94. return FALSE;
  95. }
  96. break;
  97. default:
  98. return FALSE;
  99. }
  100. return TRUE;
  101. }
  102. //
  103. // Internal Function(s):
  104. //
  105. static BOOL OnInit(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  106. {
  107. INT i;
  108. // Decide if we check Regional Settings checkbox
  109. //
  110. if (( GetPrivateProfileInt(INI_SEC_OPTIONS, INI_KEY_REGIONAL, 0, GET_FLAG(OPK_BATCHMODE) ? g_App.szOpkWizIniFile : g_App.szOobeInfoIniFile) == 1 ) )
  111. CheckDlgButton(hwnd, IDC_SCREEN_REGIONAL, TRUE);
  112. // Decide if we check Time Zone Settings checkbox
  113. //
  114. if (( GetPrivateProfileInt(INI_SEC_OPTIONS, INI_KEY_TIMEZONE, 1, GET_FLAG(OPK_BATCHMODE) ? g_App.szOpkWizIniFile : g_App.szOobeInfoIniFile) == 1 ) )
  115. CheckDlgButton(hwnd, IDC_SCREEN_TIMEZONE, TRUE);
  116. // Loop through each of the list boxes and load them
  117. //
  118. for( i = 0; i < AS(g_OobeOptions); i++)
  119. {
  120. // Load the list box using the items in the global oobe structure
  121. //
  122. LoadListBox(hwnd, g_OobeOptions[i]);
  123. }
  124. // Always return false to WM_INITDIALOG.
  125. //
  126. return FALSE;
  127. }
  128. static void OnNext(HWND hwnd)
  129. {
  130. INT iReturn,
  131. i;
  132. LONG lItemData = -1;
  133. TCHAR szItemData[MAX_PATH] = NULLSTR;
  134. HRESULT hrPrintf;
  135. // Loop through each of the OOBE options and save them off
  136. //
  137. for( i = 0; i < AS(g_OobeOptions); i++)
  138. {
  139. // Set the default values
  140. //
  141. lItemData = -1;
  142. szItemData[0] = NULLCHR;
  143. // Check to see what the current item selection is
  144. //
  145. if ( (iReturn = (INT) SendDlgItemMessage(hwnd, g_OobeOptions[i].ListBox, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0)) != CB_ERR )
  146. {
  147. // Get the DefaultLocale
  148. //
  149. lItemData = (INT) SendDlgItemMessage(hwnd, g_OobeOptions[i].ListBox, CB_GETITEMDATA, (WPARAM) iReturn, (LPARAM) 0);
  150. // Convert the item data from a long to a string
  151. //
  152. if ( lItemData != CB_ERR )
  153. hrPrintf=StringCchPrintf(szItemData, AS(szItemData), g_OobeOptions[i].lpOutputFormat, lItemData);
  154. }
  155. // Write out the settings to the INF files
  156. //
  157. WritePrivateProfileString(INI_SEC_OPTIONS, g_OobeOptions[i].lpDefaultKey, szItemData, g_App.szOobeInfoIniFile);
  158. WritePrivateProfileString(INI_SEC_OPTIONS, g_OobeOptions[i].lpDefaultKey, szItemData, g_App.szOpkWizIniFile);
  159. }
  160. // Write regional settings to the INF files
  161. //
  162. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_REGIONAL, ( IsDlgButtonChecked(hwnd, IDC_SCREEN_REGIONAL) == BST_CHECKED ) ? STR_ONE : STR_ZERO, g_App.szOobeInfoIniFile);
  163. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_REGIONAL, ( IsDlgButtonChecked(hwnd, IDC_SCREEN_REGIONAL) == BST_CHECKED ) ? STR_ONE : STR_ZERO, g_App.szOpkWizIniFile);
  164. // Write time zone settings to the INF files
  165. //
  166. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_TIMEZONE, ( IsDlgButtonChecked(hwnd, IDC_SCREEN_TIMEZONE) == BST_CHECKED ) ? STR_ONE : STR_ZERO, g_App.szOobeInfoIniFile);
  167. WritePrivateProfileString(INI_SEC_OPTIONS, INI_KEY_TIMEZONE, ( IsDlgButtonChecked(hwnd, IDC_SCREEN_TIMEZONE) == BST_CHECKED ) ? STR_ONE : STR_ZERO, g_App.szOpkWizIniFile);
  168. }
  169. static void LoadListBox(HWND hwnd, OOBEOPTIONS OobeOptions)
  170. {
  171. INT index = -1,
  172. iReturn;
  173. LPTSTR lpBuffer = NULL;
  174. HINF hInf = NULL;
  175. LONG lReturn = 0;
  176. DWORD dwErr = 0,
  177. dwItemsAdded = 0;
  178. BOOL bLoop = 0;
  179. INFCONTEXT InfContext;
  180. TCHAR szBuffer[MAX_PATH] = NULLSTR,
  181. szDefaultIndex[MAX_PATH]= NULLSTR,
  182. szTemp[MAX_PATH] = NULLSTR;
  183. HRESULT hrPrintf;
  184. // If we don't have any of the following values, we must return
  185. //
  186. if ( !hwnd || !OobeOptions.ListBox || !OobeOptions.lplrListItems || !OobeOptions.dwListSize || !OobeOptions.lpDefaultKey )
  187. return;
  188. // Get the default value for this field from the INF file
  189. //
  190. GetPrivateProfileString(INI_SEC_OPTIONS, OobeOptions.lpDefaultKey, NULLSTR, szDefaultIndex, AS(szDefaultIndex), GET_FLAG(OPK_BATCHMODE) ? g_App.szOpkWizIniFile : g_App.szOobeInfoIniFile);
  191. // We need to always add the default key, "User Default"
  192. //
  193. if ( lpBuffer = AllocateString(NULL, OobeOptions.lplrListItems[0].uId) )
  194. {
  195. // If we allocated the string add the item to the list
  196. //
  197. if ( (iReturn = (INT) SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_ADDSTRING, (WPARAM) 0, (LPARAM) lpBuffer)) >= 0 )
  198. {
  199. SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_SETCURSEL, (WPARAM) iReturn, (LPARAM) 0);
  200. // Add associated data along with the string to the combo box
  201. //
  202. SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_SETITEMDATA, (WPARAM) iReturn, (LPARAM) OobeOptions.lplrListItems[0].Index);
  203. }
  204. FREE(lpBuffer);
  205. }
  206. // Open the inf file and determine if the section that we're looking for is there.
  207. //
  208. if ( OobeOptions.lpAlternateSection && *(OobeOptions.lpAlternateSection) && (hInf = SetupOpenInfFile(g_App.szOpkInputInfFile, NULL, INF_STYLE_OLDNT | INF_STYLE_WIN4, &dwErr)) != INVALID_HANDLE_VALUE )
  209. {
  210. // Loop through each item in the list
  211. //
  212. for ( bLoop = SetupFindFirstLine(hInf, OobeOptions.lpAlternateSection, NULL, &InfContext);
  213. bLoop;
  214. bLoop = SetupFindNextLine(&InfContext, &InfContext) )
  215. {
  216. // Get the string field and the number representing it and add it to the list
  217. //
  218. if ( (SetupGetStringField(&InfContext, 1, szBuffer, AS(szBuffer), NULL)) && (szBuffer[0]) &&
  219. (SetupGetIntField(&InfContext, 2, &index)) && ( index >= 0 ) &&
  220. ((iReturn = (INT) SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_ADDSTRING, (WPARAM) 0, (LPARAM) szBuffer)) >= 0)
  221. )
  222. {
  223. // Add associated data along with the string to the combo box
  224. //
  225. SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_SETITEMDATA, (WPARAM) iReturn, (LPARAM) index);
  226. // Format the current value so that we can compare it to the default value
  227. //
  228. hrPrintf=StringCchPrintf(szTemp, AS(szTemp), OobeOptions.lpOutputFormat, index);
  229. // Compare the default value to the current value just added to the list box
  230. //
  231. if ( lstrcmpi(szTemp, szDefaultIndex) == 0 )
  232. {
  233. // Set this as the default value
  234. //
  235. SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_SETCURSEL, (WPARAM) iReturn, (LPARAM) 0);
  236. }
  237. dwItemsAdded++;
  238. }
  239. }
  240. SetupCloseInfFile(hInf);
  241. }
  242. // If we didn't add items through the inf, use the defaults in the resource
  243. //
  244. if ( !dwItemsAdded )
  245. {
  246. // Loop through each of the items in the list
  247. //
  248. for ( index=1; index < (OobeOptions.dwListSize); index++ )
  249. {
  250. // Allocate a string for the resource identifier and add it to the list
  251. //
  252. if ( (lpBuffer = AllocateString(NULL, OobeOptions.lplrListItems[index].uId)) &&
  253. ((iReturn = (INT) SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_ADDSTRING, (WPARAM) 0, (LPARAM) lpBuffer)) >= 0))
  254. {
  255. // Add associated data along with the string to the combo box
  256. //
  257. SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_SETITEMDATA, (WPARAM) iReturn, (LPARAM) OobeOptions.lplrListItems[index].Index);
  258. // Format the current value so that we can compare it to the default value
  259. //
  260. hrPrintf=StringCchPrintf(szTemp, AS(szTemp), OobeOptions.lpOutputFormat, OobeOptions.lplrListItems[index].Index);
  261. // Compare the default value to the current value just added to the list box
  262. //
  263. if ( lstrcmpi(szTemp, szDefaultIndex) == 0 )
  264. {
  265. // Set this as the default value
  266. //
  267. SendDlgItemMessage(hwnd, OobeOptions.ListBox, CB_SETCURSEL, (WPARAM) iReturn, (LPARAM) 0);
  268. }
  269. }
  270. // Clean up the allocated string
  271. //
  272. FREE(lpBuffer);
  273. }
  274. }
  275. }