mfplat/sample: Optimize copying to 2d buffer.
[wine.git] / programs / winecfg / appdefaults.c
blob4900c1e14fd5314f9f8c1c96155ef3cdaca8c2b0
1 /*
2 * WineCfg app settings tabsheet
4 * Copyright 2004 Robert van Herk
5 * Copyright 2004 Chris Morgan
6 * Copyright 2004 Mike Hearn
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.
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.
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
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26 #include <commdlg.h>
27 #include <wine/debug.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <assert.h>
31 #include "winecfg.h"
32 #include "resource.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
36 struct win_version
38 const WCHAR *szVersion;
39 const WCHAR *szDescription;
40 const WCHAR *szCurrentVersion;
41 DWORD dwMajorVersion;
42 DWORD dwMinorVersion;
43 DWORD dwBuildNumber;
44 DWORD dwPlatformId;
45 const WCHAR *szCSDVersion;
46 WORD wServicePackMajor;
47 WORD wServicePackMinor;
48 const WCHAR *szProductType;
51 static const struct win_version win_versions[] =
53 { L"win11", L"Windows 11", L"6.3", 10, 0, 22000, VER_PLATFORM_WIN32_NT, L"", 0, 0, L"WinNT"},
54 { L"win10", L"Windows 10", L"6.3", 10, 0, 19043, VER_PLATFORM_WIN32_NT, L"", 0, 0, L"WinNT"},
55 { L"win81", L"Windows 8.1", NULL, 6, 3, 9600, VER_PLATFORM_WIN32_NT, L"", 0, 0, L"WinNT"},
56 { L"win8", L"Windows 8", NULL, 6, 2, 9200, VER_PLATFORM_WIN32_NT, L"", 0, 0, L"WinNT"},
57 { L"win2008r2", L"Windows 2008 R2", NULL, 6, 1, 7601, VER_PLATFORM_WIN32_NT, L"Service Pack 1", 1, 0, L"ServerNT"},
58 { L"win7", L"Windows 7", NULL, 6, 1, 7601, VER_PLATFORM_WIN32_NT, L"Service Pack 1", 1, 0, L"WinNT"},
59 { L"win2008", L"Windows 2008", NULL, 6, 0, 6002, VER_PLATFORM_WIN32_NT, L"Service Pack 2", 2, 0, L"ServerNT"},
60 { L"vista", L"Windows Vista", NULL, 6, 0, 6002, VER_PLATFORM_WIN32_NT, L"Service Pack 2", 2, 0, L"WinNT"},
61 { L"win2003", L"Windows 2003", NULL, 5, 2, 3790, VER_PLATFORM_WIN32_NT, L"Service Pack 2", 2, 0, L"ServerNT"},
62 #ifdef _WIN64
63 { L"winxp64", L"Windows XP", NULL, 5, 2, 3790, VER_PLATFORM_WIN32_NT, L"Service Pack 2", 2, 0, L"WinNT"},
64 #else
65 { L"winxp", L"Windows XP", NULL, 5, 1, 2600, VER_PLATFORM_WIN32_NT, L"Service Pack 3", 3, 0, L"WinNT"},
66 { L"win2k", L"Windows 2000", NULL, 5, 0, 2195, VER_PLATFORM_WIN32_NT, L"Service Pack 4", 4, 0, L"WinNT"},
67 { L"winme", L"Windows ME", NULL, 4, 90, 3000, VER_PLATFORM_WIN32_WINDOWS, L" ", 0, 0, L""},
68 { L"win98", L"Windows 98", NULL, 4, 10, 2222, VER_PLATFORM_WIN32_WINDOWS, L" A ", 0, 0, L""},
69 { L"win95", L"Windows 95", NULL, 4, 0, 950, VER_PLATFORM_WIN32_WINDOWS, L"", 0, 0, L""},
70 { L"nt40", L"Windows NT 4.0", NULL, 4, 0, 1381, VER_PLATFORM_WIN32_NT, L"Service Pack 6a", 6, 0, L"WinNT"},
71 { L"nt351", L"Windows NT 3.51", NULL, 3, 51, 1057, VER_PLATFORM_WIN32_NT, L"Service Pack 5", 5, 0, L"WinNT"},
72 { L"win31", L"Windows 3.1", NULL, 3, 10, 0, VER_PLATFORM_WIN32s, L"Win32s 1.3", 0, 0, L""},
73 { L"win30", L"Windows 3.0", NULL, 3, 0, 0, VER_PLATFORM_WIN32s, L"Win32s 1.3", 0, 0, L""},
74 { L"win20", L"Windows 2.0", NULL, 2, 0, 0, VER_PLATFORM_WIN32s, L"Win32s 1.3", 0, 0, L""}
75 #endif
78 #define DEFAULT_WIN_VERSION L"win10"
80 static const WCHAR szKey9x[] = L"Software\\Microsoft\\Windows\\CurrentVersion";
81 static const WCHAR szKeyNT[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion";
82 static const WCHAR szKeyProdNT[] = L"System\\CurrentControlSet\\Control\\ProductOptions";
84 static DWORD get_reg_dword( HKEY root, const WCHAR *subkey, const WCHAR *value )
86 HKEY hkey;
87 DWORD ret, len = sizeof(ret), type;
89 if (RegOpenKeyExW( root, subkey, 0, KEY_QUERY_VALUE, &hkey )) return 0;
90 if (RegQueryValueExW( hkey, value, NULL, &type, (BYTE *)&ret, &len ) || type != REG_DWORD) ret = 0;
91 RegCloseKey( hkey );
92 return ret;
95 static int get_registry_version(void)
97 int i, best = -1, platform, major = 0, minor = 0, build = 0;
98 WCHAR *p, *ver, *type = NULL;
100 if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", NULL )))
102 WCHAR *build_str;
104 platform = VER_PLATFORM_WIN32_NT;
106 major = get_reg_dword( HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMajorVersionNumber" );
107 minor = get_reg_dword( HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMinorVersionNumber" );
109 build_str = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuildNumber", NULL );
110 build = wcstol(build_str, NULL, 10);
112 type = get_reg_key( HKEY_LOCAL_MACHINE, szKeyProdNT, L"ProductType", NULL );
114 else if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKey9x, L"VersionNumber", NULL )))
115 platform = VER_PLATFORM_WIN32_WINDOWS;
116 else
117 return -1;
119 if (!major)
121 if ((p = wcschr( ver, '.' )))
123 WCHAR *minor_str = p;
124 *minor_str++ = 0;
125 if ((p = wcschr( minor_str, '.' )))
127 WCHAR *build_str = p;
128 *build_str++ = 0;
129 build = wcstol(build_str, NULL, 10);
131 minor = wcstol(minor_str, NULL, 10);
133 major = wcstol(ver, NULL, 10);
136 for (i = 0; i < ARRAY_SIZE(win_versions); i++)
138 if (win_versions[i].dwPlatformId != platform) continue;
139 if (win_versions[i].dwMajorVersion != major) continue;
140 if (type && wcsicmp(win_versions[i].szProductType, type)) continue;
141 best = i;
142 if ((win_versions[i].dwMinorVersion == minor) &&
143 (win_versions[i].dwBuildNumber == build))
144 return i;
146 return best;
149 static void update_comboboxes(HWND dialog)
151 int i, ver;
152 WCHAR *winver;
154 /* retrieve the registry values */
155 winver = get_reg_key(config_key, keypath(L""), L"Version", L"");
156 ver = get_registry_version();
158 if (!winver || !winver[0])
160 free(winver);
162 if (current_app) /* no explicit setting */
164 WINE_TRACE("setting winver combobox to default\n");
165 SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL, 0, 0);
166 return;
168 if (ver != -1) winver = wcsdup(win_versions[ver].szVersion);
169 else winver = wcsdup(DEFAULT_WIN_VERSION);
171 WINE_TRACE("winver is %s\n", debugstr_w(winver));
173 /* normalize the version strings */
174 for (i = 0; i < ARRAY_SIZE(win_versions); i++)
176 if (!wcsicmp(win_versions[i].szVersion, winver))
178 SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL,
179 i + (current_app?1:0), 0);
180 WINE_TRACE("match with %s\n", debugstr_w(win_versions[i].szVersion));
181 break;
185 free(winver);
188 static void
189 init_comboboxes (HWND dialog)
191 int i;
193 SendDlgItemMessageW(dialog, IDC_WINVER, CB_RESETCONTENT, 0, 0);
195 /* add the default entries (automatic) which correspond to no setting */
196 if (current_app)
198 WCHAR str[256];
199 LoadStringW(GetModuleHandleW(NULL), IDS_USE_GLOBAL_SETTINGS, str, ARRAY_SIZE(str));
200 SendDlgItemMessageW (dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM)str);
203 for (i = 0; i < ARRAY_SIZE(win_versions); i++)
205 SendDlgItemMessageW(dialog, IDC_WINVER, CB_ADDSTRING,
206 0, (LPARAM) win_versions[i].szDescription);
210 static void add_listview_item(HWND listview, WCHAR *text, void *association)
212 LVITEMW item;
214 item.mask = LVIF_TEXT | LVIF_PARAM;
215 item.pszText = text;
216 item.cchTextMax = lstrlenW(text);
217 item.lParam = (LPARAM) association;
218 item.iItem = SendMessageW( listview, LVM_GETITEMCOUNT, 0, 0 );
219 item.iSubItem = 0;
221 SendMessageW(listview, LVM_INSERTITEMW, 0, (LPARAM) &item);
224 /* Called when the application is initialized (cannot reinit!) */
225 static void init_appsheet(HWND dialog)
227 HWND listview;
228 LVITEMW item;
229 HKEY key;
230 int i;
231 DWORD size;
232 WCHAR appname[1024];
234 WINE_TRACE("()\n");
236 listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
238 /* we use the lparam field of the item so we can alter the presentation later and not change code
239 * for instance, to use the tile view or to display the EXEs embedded 'display name' */
240 LoadStringW(GetModuleHandleW(NULL), IDS_DEFAULT_SETTINGS, appname, ARRAY_SIZE(appname));
241 add_listview_item(listview, appname, NULL);
243 /* because this list is only populated once, it's safe to bypass the settings list here */
244 if (RegOpenKeyW(config_key, L"AppDefaults", &key) == ERROR_SUCCESS)
246 i = 0;
247 size = ARRAY_SIZE(appname);
248 while (RegEnumKeyExW (key, i, appname, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
250 add_listview_item(listview, appname, wcsdup(appname));
252 i++;
253 size = ARRAY_SIZE(appname);
256 RegCloseKey(key);
259 init_comboboxes(dialog);
261 /* Select the default settings listview item */
262 item.iItem = 0;
263 item.iSubItem = 0;
264 item.mask = LVIF_STATE;
265 item.state = LVIS_SELECTED | LVIS_FOCUSED;
266 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
268 SendMessageW(listview, LVM_SETITEMW, 0, (LPARAM) &item);
271 /* there has to be an easier way than this */
272 static int get_listview_selection(HWND listview)
274 int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
275 int i;
277 for (i = 0; i < count; i++)
279 if (SendMessageW( listview, LVM_GETITEMSTATE, i, LVIS_SELECTED )) return i;
282 return -1;
286 /* called when the user selects a different application */
287 static void on_selection_change(HWND dialog, HWND listview)
289 LVITEMW item;
290 WCHAR* oldapp = current_app;
292 WINE_TRACE("()\n");
294 item.iItem = get_listview_selection(listview);
295 item.iSubItem = 0;
296 item.mask = LVIF_PARAM;
298 WINE_TRACE("item.iItem=%d\n", item.iItem);
300 if (item.iItem == -1) return;
302 SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
304 current_app = (WCHAR*) item.lParam;
306 if (current_app)
308 WINE_TRACE("current_app is now %s\n", wine_dbgstr_w (current_app));
309 enable(IDC_APP_REMOVEAPP);
311 else
313 WINE_TRACE("current_app=NULL, editing global settings\n");
314 /* focus will never be on the button in this callback so it's safe */
315 disable(IDC_APP_REMOVEAPP);
318 /* reset the combo boxes if we changed from/to global/app-specific */
320 if ((oldapp && !current_app) || (!oldapp && current_app))
321 init_comboboxes(dialog);
323 update_comboboxes(dialog);
325 set_window_title(dialog);
328 static BOOL list_contains_file(HWND listview, WCHAR *filename)
330 LVFINDINFOW find_info = { LVFI_STRING, filename, 0, {0, 0}, 0 };
331 int index;
333 index = ListView_FindItemW(listview, -1, &find_info);
335 return (index != -1);
338 static void on_add_app_click(HWND dialog)
340 WCHAR filetitle[MAX_PATH];
341 WCHAR file[MAX_PATH];
342 WCHAR programsFilter[100], filter[MAX_PATH];
343 WCHAR selectExecutableStr[100];
345 OPENFILENAMEW ofn = { sizeof(OPENFILENAMEW),
346 dialog, /*hInst*/0, 0, NULL, 0, 0, NULL,
347 0, NULL, 0, L"C:\\", 0,
348 OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_ENABLESIZING,
349 0, 0, NULL, 0, NULL };
351 LoadStringW (GetModuleHandleW(NULL), IDS_SELECT_EXECUTABLE, selectExecutableStr,
352 ARRAY_SIZE(selectExecutableStr));
353 LoadStringW (GetModuleHandleW(NULL), IDS_EXECUTABLE_FILTER, programsFilter,
354 ARRAY_SIZE(programsFilter));
355 swprintf( filter, MAX_PATH, L"%s%c*.exe;*.exe.so%c", programsFilter, 0, 0 );
357 ofn.lpstrTitle = selectExecutableStr;
358 ofn.lpstrFilter = filter;
359 ofn.lpstrFileTitle = filetitle;
360 ofn.lpstrFileTitle[0] = '\0';
361 ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
362 ofn.lpstrFile = file;
363 ofn.lpstrFile[0] = '\0';
364 ofn.nMaxFile = ARRAY_SIZE(file);
366 if (GetOpenFileNameW (&ofn))
368 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
369 int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
370 WCHAR* new_app;
371 LVITEMW item;
373 if (list_contains_file(listview, filetitle))
374 return;
376 new_app = wcsdup(filetitle);
378 WINE_TRACE("adding %s\n", wine_dbgstr_w (new_app));
380 add_listview_item(listview, new_app, new_app);
382 item.mask = LVIF_STATE;
383 item.state = LVIS_SELECTED | LVIS_FOCUSED;
384 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
385 SendMessageW(listview, LVM_SETITEMSTATE, count, (LPARAM)&item );
387 SetFocus(listview);
389 else WINE_TRACE("user cancelled\n");
392 static void on_remove_app_click(HWND dialog)
394 HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
395 int selection = get_listview_selection(listview);
396 LVITEMW item;
398 item.iItem = selection;
399 item.iSubItem = 0;
400 item.mask = LVIF_PARAM;
402 WINE_TRACE("selection=%d\n", selection);
404 assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */
406 set_reg_key(config_key, keypath(L""), NULL, NULL); /* delete the section */
407 SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
408 free((void*)item.lParam);
409 SendMessageW(listview, LVM_DELETEITEM, selection, 0);
410 item.mask = LVIF_STATE;
411 item.state = LVIS_SELECTED | LVIS_FOCUSED;
412 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
413 SendMessageW(listview, LVM_SETITEMSTATE, 0, (LPARAM)&item);
415 SetFocus(listview);
416 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
419 static void set_winver(const struct win_version *version)
421 static const WCHAR szKeyWindNT[] = L"System\\CurrentControlSet\\Control\\Windows";
422 static const WCHAR szKeyEnvNT[] = L"System\\CurrentControlSet\\Control\\Session Manager\\Environment";
423 WCHAR buffer[40];
425 switch (version->dwPlatformId)
427 case VER_PLATFORM_WIN32_WINDOWS:
428 swprintf(buffer, ARRAY_SIZE(buffer), L"%d.%d.%d", version->dwMajorVersion,
429 version->dwMinorVersion, version->dwBuildNumber);
430 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"VersionNumber", buffer);
431 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"SubVersionNumber", version->szCSDVersion);
432 swprintf(buffer, ARRAY_SIZE(buffer), L"Microsoft %s", version->szDescription);
433 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"ProductName", buffer);
435 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CSDVersion", NULL);
436 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", NULL);
437 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMajorVersionNumber", NULL);
438 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMinorVersionNumber", NULL);
439 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuild", NULL);
440 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuildNumber", NULL);
441 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"ProductName", NULL);
442 set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, L"ProductType", NULL);
443 set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, L"CSDVersion", NULL);
444 set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, L"OS", NULL);
445 set_reg_key(config_key, keypath(L""), L"Version", NULL);
446 break;
448 case VER_PLATFORM_WIN32_NT:
449 if (version->szCurrentVersion)
450 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", version->szCurrentVersion);
451 else
453 swprintf(buffer, ARRAY_SIZE(buffer), L"%d.%d", version->dwMajorVersion, version->dwMinorVersion);
454 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", buffer);
456 set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMajorVersionNumber", version->dwMajorVersion);
457 set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMinorVersionNumber", version->dwMinorVersion);
458 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CSDVersion", version->szCSDVersion);
459 swprintf(buffer, ARRAY_SIZE(buffer), L"%d", version->dwBuildNumber);
460 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuild", buffer);
461 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuildNumber", buffer);
462 swprintf(buffer, ARRAY_SIZE(buffer), L"Microsoft %s", version->szDescription);
463 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"ProductName", buffer);
464 set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, L"ProductType", version->szProductType);
465 set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyWindNT, L"CSDVersion",
466 MAKEWORD( version->wServicePackMinor,
467 version->wServicePackMajor ));
468 set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, L"OS", L"Windows_NT");
470 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"VersionNumber", NULL);
471 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"SubVersionNumber", NULL);
472 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"ProductName", NULL);
473 set_reg_key(config_key, keypath(L""), L"Version", NULL);
474 break;
476 case VER_PLATFORM_WIN32s:
477 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CSDVersion", NULL);
478 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", NULL);
479 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuild", NULL);
480 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuildNumber", NULL);
481 set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"ProductName", NULL);
482 set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, L"ProductType", NULL);
483 set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, L"CSDVersion", NULL);
484 set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, L"OS", NULL);
485 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"VersionNumber", NULL);
486 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"SubVersionNumber", NULL);
487 set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"ProductName", NULL);
488 set_reg_key(config_key, keypath(L""), L"Version", version->szVersion);
489 break;
493 BOOL set_winver_from_string(const WCHAR *version)
495 int i;
497 WINE_TRACE("desired winver: %s\n", debugstr_w(version));
499 for (i = 0; i < ARRAY_SIZE(win_versions); i++)
501 if (!wcsicmp(win_versions[i].szVersion, version))
503 WINE_TRACE("match with %s\n", debugstr_w(win_versions[i].szVersion));
504 set_winver(&win_versions[i]);
505 apply();
506 return TRUE;
510 return FALSE;
513 void print_windows_versions(void)
515 int i;
517 for (i = 0; i < ARRAY_SIZE(win_versions); i++)
519 wprintf(L" %10s %s\n", win_versions[i].szVersion, win_versions[i].szDescription);
523 void print_current_winver(void)
525 WCHAR *winver = get_reg_key(config_key, keypath(L""), L"Version", L"");
527 if (!winver || !winver[0])
529 int ver = get_registry_version();
530 wprintf(L"%s\n", ver == -1 ? DEFAULT_WIN_VERSION : win_versions[ver].szVersion);
532 else
533 wprintf(L"%s\n", winver);
535 free(winver);
538 static void on_winver_change(HWND dialog)
540 int selection = SendDlgItemMessageW(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0);
542 if (current_app)
544 if (!selection)
546 WINE_TRACE("default selected so removing current setting\n");
547 set_reg_key(config_key, keypath(L""), L"Version", NULL);
549 else
551 WINE_TRACE("setting Version key to value %s\n", debugstr_w(win_versions[selection-1].szVersion));
552 set_reg_key(config_key, keypath(L""), L"Version", win_versions[selection-1].szVersion);
555 else /* global version only */
557 set_winver(&win_versions[selection]);
560 /* enable the apply button */
561 SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
564 INT_PTR CALLBACK
565 AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
567 switch (uMsg)
569 case WM_INITDIALOG:
570 init_appsheet(hDlg);
571 break;
573 case WM_SHOWWINDOW:
574 set_window_title(hDlg);
575 break;
577 case WM_NOTIFY:
578 switch (((LPNMHDR)lParam)->code)
580 case LVN_ITEMCHANGED:
581 on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW));
582 break;
583 case PSN_APPLY:
584 apply();
585 SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
586 break;
589 break;
591 case WM_COMMAND:
592 switch(HIWORD(wParam))
594 case CBN_SELCHANGE:
595 switch(LOWORD(wParam))
597 case IDC_WINVER:
598 on_winver_change(hDlg);
599 break;
601 case BN_CLICKED:
602 switch(LOWORD(wParam))
604 case IDC_APP_ADDAPP:
605 on_add_app_click(hDlg);
606 break;
607 case IDC_APP_REMOVEAPP:
608 on_remove_app_click(hDlg);
609 break;
611 break;
614 break;
617 return 0;