appdefaults.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. * WineCfg app settings tabsheet
  3. *
  4. * Copyright 2004 Robert van Herk
  5. * Copyright 2004 Chris Morgan
  6. * Copyright 2004 Mike Hearn
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  21. *
  22. */
  23. #define WIN32_LEAN_AND_MEAN
  24. #include <windows.h>
  25. #include <commdlg.h>
  26. #include <wine/debug.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <assert.h>
  30. #include "wine/unicode.h"
  31. #include "winecfg.h"
  32. #include "resource.h"
  33. WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
  34. struct win_version
  35. {
  36. const char *szVersion;
  37. const char *szDescription;
  38. DWORD dwMajorVersion;
  39. DWORD dwMinorVersion;
  40. DWORD dwBuildNumber;
  41. DWORD dwPlatformId;
  42. const char *szCSDVersion;
  43. WORD wServicePackMajor;
  44. WORD wServicePackMinor;
  45. const char *szProductType;
  46. };
  47. static const struct win_version win_versions[] =
  48. {
  49. { "win10", "Windows 10", 10, 0, 0x42EE,VER_PLATFORM_WIN32_NT, "", 0, 0, "WinNT"},
  50. { "win81", "Windows 8.1", 6, 3, 0x2580,VER_PLATFORM_WIN32_NT, "", 0, 0, "WinNT"},
  51. { "win8", "Windows 8", 6, 2, 0x23F0,VER_PLATFORM_WIN32_NT, "", 0, 0, "WinNT"},
  52. { "win2008r2", "Windows 2008 R2", 6, 1, 0x1DB1,VER_PLATFORM_WIN32_NT, "Service Pack 1", 1, 0, "ServerNT"},
  53. { "win7", "Windows 7", 6, 1, 0x1DB1,VER_PLATFORM_WIN32_NT, "Service Pack 1", 1, 0, "WinNT"},
  54. { "win2008", "Windows 2008", 6, 0, 0x1772,VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "ServerNT"},
  55. { "vista", "Windows Vista", 6, 0, 0x1772,VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "WinNT"},
  56. { "win2003", "Windows 2003", 5, 2, 0xECE, VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "ServerNT"},
  57. #ifdef _WIN64
  58. { "winxp64", "Windows XP", 5, 2, 0xECE, VER_PLATFORM_WIN32_NT, "Service Pack 2", 2, 0, "WinNT"},
  59. #else
  60. { "winxp", "Windows XP", 5, 1, 0xA28, VER_PLATFORM_WIN32_NT, "Service Pack 3", 3, 0, "WinNT"},
  61. { "win2k", "Windows 2000", 5, 0, 0x893, VER_PLATFORM_WIN32_NT, "Service Pack 4", 4, 0, "WinNT"},
  62. { "winme", "Windows ME", 4, 90, 0xBB8, VER_PLATFORM_WIN32_WINDOWS, " ", 0, 0, ""},
  63. { "win98", "Windows 98", 4, 10, 0x8AE, VER_PLATFORM_WIN32_WINDOWS, " A ", 0, 0, ""},
  64. { "win95", "Windows 95", 4, 0, 0x3B6, VER_PLATFORM_WIN32_WINDOWS, "", 0, 0, ""},
  65. { "nt40", "Windows NT 4.0", 4, 0, 0x565, VER_PLATFORM_WIN32_NT, "Service Pack 6a", 6, 0, "WinNT"},
  66. { "nt351", "Windows NT 3.51", 3, 51, 0x421, VER_PLATFORM_WIN32_NT, "Service Pack 5", 5, 0, "WinNT"},
  67. { "win31", "Windows 3.1", 3, 10, 0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""},
  68. { "win30", "Windows 3.0", 3, 0, 0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""},
  69. { "win20", "Windows 2.0", 2, 0, 0, VER_PLATFORM_WIN32s, "Win32s 1.3", 0, 0, ""}
  70. #endif
  71. };
  72. static const char szKey9x[] = "Software\\Microsoft\\Windows\\CurrentVersion";
  73. static const char szKeyNT[] = "Software\\Microsoft\\Windows NT\\CurrentVersion";
  74. static const char szKeyProdNT[] = "System\\CurrentControlSet\\Control\\ProductOptions";
  75. static int get_registry_version(void)
  76. {
  77. int i, best = -1, platform, major, minor = 0, build = 0;
  78. char *p, *ver, *type = NULL;
  79. if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL )))
  80. {
  81. char *build_str;
  82. platform = VER_PLATFORM_WIN32_NT;
  83. build_str = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL );
  84. build = atoi(build_str);
  85. type = get_reg_key( HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL );
  86. }
  87. else if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL )))
  88. platform = VER_PLATFORM_WIN32_WINDOWS;
  89. else
  90. return -1;
  91. if ((p = strchr( ver, '.' )))
  92. {
  93. char *minor_str = p;
  94. *minor_str++ = 0;
  95. if ((p = strchr( minor_str, '.' )))
  96. {
  97. char *build_str = p;
  98. *build_str++ = 0;
  99. build = atoi(build_str);
  100. }
  101. minor = atoi(minor_str);
  102. }
  103. major = atoi(ver);
  104. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  105. {
  106. if (win_versions[i].dwPlatformId != platform) continue;
  107. if (win_versions[i].dwMajorVersion != major) continue;
  108. if (type && strcasecmp(win_versions[i].szProductType, type)) continue;
  109. best = i;
  110. if ((win_versions[i].dwMinorVersion == minor) &&
  111. (win_versions[i].dwBuildNumber == build))
  112. return i;
  113. }
  114. return best;
  115. }
  116. static void update_comboboxes(HWND dialog)
  117. {
  118. int i, ver;
  119. char *winver;
  120. /* retrieve the registry values */
  121. winver = get_reg_key(config_key, keypath(""), "Version", "");
  122. ver = get_registry_version();
  123. if (!winver || !winver[0])
  124. {
  125. HeapFree(GetProcessHeap(), 0, winver);
  126. if (current_app) /* no explicit setting */
  127. {
  128. WINE_TRACE("setting winver combobox to default\n");
  129. SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL, 0, 0);
  130. return;
  131. }
  132. if (ver != -1) winver = strdupA( win_versions[ver].szVersion );
  133. else winver = strdupA("win7");
  134. }
  135. WINE_TRACE("winver is %s\n", winver);
  136. /* normalize the version strings */
  137. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  138. {
  139. if (!strcasecmp (win_versions[i].szVersion, winver))
  140. {
  141. SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL,
  142. i + (current_app?1:0), 0);
  143. WINE_TRACE("match with %s\n", win_versions[i].szVersion);
  144. break;
  145. }
  146. }
  147. HeapFree(GetProcessHeap(), 0, winver);
  148. }
  149. static void
  150. init_comboboxes (HWND dialog)
  151. {
  152. int i;
  153. SendDlgItemMessageW(dialog, IDC_WINVER, CB_RESETCONTENT, 0, 0);
  154. /* add the default entries (automatic) which correspond to no setting */
  155. if (current_app)
  156. {
  157. WCHAR str[256];
  158. LoadStringW(GetModuleHandleW(NULL), IDS_USE_GLOBAL_SETTINGS, str, ARRAY_SIZE(str));
  159. SendDlgItemMessageW (dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM)str);
  160. }
  161. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  162. {
  163. SendDlgItemMessageA(dialog, IDC_WINVER, CB_ADDSTRING,
  164. 0, (LPARAM) win_versions[i].szDescription);
  165. }
  166. }
  167. static void add_listview_item(HWND listview, WCHAR *text, void *association)
  168. {
  169. LVITEMW item;
  170. item.mask = LVIF_TEXT | LVIF_PARAM;
  171. item.pszText = text;
  172. item.cchTextMax = lstrlenW(text);
  173. item.lParam = (LPARAM) association;
  174. item.iItem = SendMessageW( listview, LVM_GETITEMCOUNT, 0, 0 );
  175. item.iSubItem = 0;
  176. SendMessageW(listview, LVM_INSERTITEMW, 0, (LPARAM) &item);
  177. }
  178. /* Called when the application is initialized (cannot reinit!) */
  179. static void init_appsheet(HWND dialog)
  180. {
  181. HWND listview;
  182. LVITEMW item;
  183. HKEY key;
  184. int i;
  185. DWORD size;
  186. WCHAR appname[1024];
  187. WINE_TRACE("()\n");
  188. listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
  189. /* we use the lparam field of the item so we can alter the presentation later and not change code
  190. * for instance, to use the tile view or to display the EXEs embedded 'display name' */
  191. LoadStringW(GetModuleHandleW(NULL), IDS_DEFAULT_SETTINGS, appname, ARRAY_SIZE(appname));
  192. add_listview_item(listview, appname, NULL);
  193. /* because this list is only populated once, it's safe to bypass the settings list here */
  194. if (RegOpenKeyA(config_key, "AppDefaults", &key) == ERROR_SUCCESS)
  195. {
  196. i = 0;
  197. size = ARRAY_SIZE(appname);
  198. while (RegEnumKeyExW (key, i, appname, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
  199. {
  200. add_listview_item(listview, appname, strdupW(appname));
  201. i++;
  202. size = ARRAY_SIZE(appname);
  203. }
  204. RegCloseKey(key);
  205. }
  206. init_comboboxes(dialog);
  207. /* Select the default settings listview item */
  208. item.iItem = 0;
  209. item.iSubItem = 0;
  210. item.mask = LVIF_STATE;
  211. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  212. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  213. SendMessageW(listview, LVM_SETITEMW, 0, (LPARAM) &item);
  214. }
  215. /* there has to be an easier way than this */
  216. static int get_listview_selection(HWND listview)
  217. {
  218. int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
  219. int i;
  220. for (i = 0; i < count; i++)
  221. {
  222. if (SendMessageW( listview, LVM_GETITEMSTATE, i, LVIS_SELECTED )) return i;
  223. }
  224. return -1;
  225. }
  226. /* called when the user selects a different application */
  227. static void on_selection_change(HWND dialog, HWND listview)
  228. {
  229. LVITEMW item;
  230. WCHAR* oldapp = current_app;
  231. WINE_TRACE("()\n");
  232. item.iItem = get_listview_selection(listview);
  233. item.iSubItem = 0;
  234. item.mask = LVIF_PARAM;
  235. WINE_TRACE("item.iItem=%d\n", item.iItem);
  236. if (item.iItem == -1) return;
  237. SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
  238. current_app = (WCHAR*) item.lParam;
  239. if (current_app)
  240. {
  241. WINE_TRACE("current_app is now %s\n", wine_dbgstr_w (current_app));
  242. enable(IDC_APP_REMOVEAPP);
  243. }
  244. else
  245. {
  246. WINE_TRACE("current_app=NULL, editing global settings\n");
  247. /* focus will never be on the button in this callback so it's safe */
  248. disable(IDC_APP_REMOVEAPP);
  249. }
  250. /* reset the combo boxes if we changed from/to global/app-specific */
  251. if ((oldapp && !current_app) || (!oldapp && current_app))
  252. init_comboboxes(dialog);
  253. update_comboboxes(dialog);
  254. set_window_title(dialog);
  255. }
  256. static BOOL list_contains_file(HWND listview, WCHAR *filename)
  257. {
  258. LVFINDINFOW find_info = { LVFI_STRING, filename, 0, {0, 0}, 0 };
  259. int index;
  260. index = ListView_FindItemW(listview, -1, &find_info);
  261. return (index != -1);
  262. }
  263. static void on_add_app_click(HWND dialog)
  264. {
  265. static const WCHAR filterW[] = {'%','s','%','c','*','.','e','x','e',';','*','.','e','x','e','.','s','o','%','c',0};
  266. WCHAR filetitle[MAX_PATH];
  267. WCHAR file[MAX_PATH];
  268. WCHAR programsFilter[100], filter[MAX_PATH];
  269. WCHAR selectExecutableStr[100];
  270. static const WCHAR pathC[] = { 'c',':','\\',0 };
  271. OPENFILENAMEW ofn = { sizeof(OPENFILENAMEW),
  272. dialog, /*hInst*/0, 0, NULL, 0, 0, NULL,
  273. 0, NULL, 0, pathC, 0,
  274. OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_ENABLESIZING,
  275. 0, 0, NULL, 0, NULL };
  276. LoadStringW (GetModuleHandleW(NULL), IDS_SELECT_EXECUTABLE, selectExecutableStr,
  277. ARRAY_SIZE(selectExecutableStr));
  278. LoadStringW (GetModuleHandleW(NULL), IDS_EXECUTABLE_FILTER, programsFilter,
  279. ARRAY_SIZE(programsFilter));
  280. snprintfW( filter, MAX_PATH, filterW, programsFilter, 0, 0 );
  281. ofn.lpstrTitle = selectExecutableStr;
  282. ofn.lpstrFilter = filter;
  283. ofn.lpstrFileTitle = filetitle;
  284. ofn.lpstrFileTitle[0] = '\0';
  285. ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
  286. ofn.lpstrFile = file;
  287. ofn.lpstrFile[0] = '\0';
  288. ofn.nMaxFile = ARRAY_SIZE(file);
  289. if (GetOpenFileNameW (&ofn))
  290. {
  291. HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
  292. int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
  293. WCHAR* new_app;
  294. LVITEMW item;
  295. if (list_contains_file(listview, filetitle))
  296. return;
  297. new_app = strdupW(filetitle);
  298. WINE_TRACE("adding %s\n", wine_dbgstr_w (new_app));
  299. add_listview_item(listview, new_app, new_app);
  300. item.mask = LVIF_STATE;
  301. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  302. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  303. SendMessageW(listview, LVM_SETITEMSTATE, count, (LPARAM)&item );
  304. SetFocus(listview);
  305. }
  306. else WINE_TRACE("user cancelled\n");
  307. }
  308. static void on_remove_app_click(HWND dialog)
  309. {
  310. HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
  311. int selection = get_listview_selection(listview);
  312. LVITEMW item;
  313. item.iItem = selection;
  314. item.iSubItem = 0;
  315. item.mask = LVIF_PARAM;
  316. WINE_TRACE("selection=%d\n", selection);
  317. assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */
  318. set_reg_key(config_key, keypath(""), NULL, NULL); /* delete the section */
  319. SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
  320. HeapFree (GetProcessHeap(), 0, (void*)item.lParam);
  321. SendMessageW(listview, LVM_DELETEITEM, selection, 0);
  322. item.mask = LVIF_STATE;
  323. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  324. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  325. SendMessageW(listview, LVM_SETITEMSTATE, 0, (LPARAM)&item);
  326. SetFocus(listview);
  327. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  328. }
  329. static void set_winver(const struct win_version *version)
  330. {
  331. static const char szKeyWindNT[] = "System\\CurrentControlSet\\Control\\Windows";
  332. static const char szKeyEnvNT[] = "System\\CurrentControlSet\\Control\\Session Manager\\Environment";
  333. char Buffer[40];
  334. switch (version->dwPlatformId)
  335. {
  336. case VER_PLATFORM_WIN32_WINDOWS:
  337. snprintf(Buffer, sizeof(Buffer), "%d.%d.%d", version->dwMajorVersion,
  338. version->dwMinorVersion, version->dwBuildNumber);
  339. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", Buffer);
  340. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", version->szCSDVersion);
  341. snprintf(Buffer, sizeof(Buffer), "Microsoft %s", version->szDescription);
  342. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", Buffer);
  343. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", NULL);
  344. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL);
  345. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentMajorVersionNumber", NULL);
  346. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentMinorVersionNumber", NULL);
  347. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuild", NULL);
  348. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL);
  349. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", NULL);
  350. set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL);
  351. set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion", NULL);
  352. set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", NULL);
  353. set_reg_key(config_key, keypath(""), "Version", NULL);
  354. break;
  355. case VER_PLATFORM_WIN32_NT:
  356. snprintf(Buffer, sizeof(Buffer), "%d.%d", version->dwMajorVersion,
  357. version->dwMinorVersion);
  358. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", Buffer);
  359. set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentMajorVersionNumber", version->dwMajorVersion);
  360. set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentMinorVersionNumber", version->dwMinorVersion);
  361. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", version->szCSDVersion);
  362. snprintf(Buffer, sizeof(Buffer), "%d", version->dwBuildNumber);
  363. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuild", Buffer);
  364. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", Buffer);
  365. snprintf(Buffer, sizeof(Buffer), "Microsoft %s", version->szDescription);
  366. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", Buffer);
  367. set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", version->szProductType);
  368. set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion",
  369. MAKEWORD( version->wServicePackMinor,
  370. version->wServicePackMajor ));
  371. set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", "Windows_NT");
  372. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL);
  373. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", NULL);
  374. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", NULL);
  375. set_reg_key(config_key, keypath(""), "Version", NULL);
  376. break;
  377. case VER_PLATFORM_WIN32s:
  378. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CSDVersion", NULL);
  379. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentVersion", NULL);
  380. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuild", NULL);
  381. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "CurrentBuildNumber", NULL);
  382. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, "ProductName", NULL);
  383. set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, "ProductType", NULL);
  384. set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, "CSDVersion", NULL);
  385. set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, "OS", NULL);
  386. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "VersionNumber", NULL);
  387. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "SubVersionNumber", NULL);
  388. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, "ProductName", NULL);
  389. set_reg_key(config_key, keypath(""), "Version", version->szVersion);
  390. break;
  391. }
  392. }
  393. BOOL set_winver_from_string(const char *version)
  394. {
  395. int i;
  396. WINE_TRACE("desired winver: '%s'\n", version);
  397. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  398. {
  399. if (!lstrcmpiA(win_versions[i].szVersion, version))
  400. {
  401. WINE_TRACE("match with %s\n", win_versions[i].szVersion);
  402. set_winver(&win_versions[i]);
  403. apply();
  404. return TRUE;
  405. }
  406. }
  407. return FALSE;
  408. }
  409. void print_windows_versions(void)
  410. {
  411. int i;
  412. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  413. {
  414. printf(" %10s %s\n", win_versions[i].szVersion, win_versions[i].szDescription);
  415. }
  416. }
  417. static void on_winver_change(HWND dialog)
  418. {
  419. int selection = SendDlgItemMessageW(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0);
  420. if (current_app)
  421. {
  422. if (!selection)
  423. {
  424. WINE_TRACE("default selected so removing current setting\n");
  425. set_reg_key(config_key, keypath(""), "Version", NULL);
  426. }
  427. else
  428. {
  429. WINE_TRACE("setting Version key to value '%s'\n", win_versions[selection-1].szVersion);
  430. set_reg_key(config_key, keypath(""), "Version", win_versions[selection-1].szVersion);
  431. }
  432. }
  433. else /* global version only */
  434. {
  435. set_winver(&win_versions[selection]);
  436. }
  437. /* enable the apply button */
  438. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  439. }
  440. INT_PTR CALLBACK
  441. AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  442. {
  443. switch (uMsg)
  444. {
  445. case WM_INITDIALOG:
  446. init_appsheet(hDlg);
  447. break;
  448. case WM_SHOWWINDOW:
  449. set_window_title(hDlg);
  450. break;
  451. case WM_NOTIFY:
  452. switch (((LPNMHDR)lParam)->code)
  453. {
  454. case LVN_ITEMCHANGED:
  455. on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW));
  456. break;
  457. case PSN_APPLY:
  458. apply();
  459. SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  460. break;
  461. }
  462. break;
  463. case WM_COMMAND:
  464. switch(HIWORD(wParam))
  465. {
  466. case CBN_SELCHANGE:
  467. switch(LOWORD(wParam))
  468. {
  469. case IDC_WINVER:
  470. on_winver_change(hDlg);
  471. break;
  472. }
  473. case BN_CLICKED:
  474. switch(LOWORD(wParam))
  475. {
  476. case IDC_APP_ADDAPP:
  477. on_add_app_click(hDlg);
  478. break;
  479. case IDC_APP_REMOVEAPP:
  480. on_remove_app_click(hDlg);
  481. break;
  482. }
  483. break;
  484. }
  485. break;
  486. }
  487. return 0;
  488. }