2b8817730144a822406c93c7e254b49de47daef2
[reactos.git] / reactos / base / shell / explorer / settings.cpp
1 /*
2 * ReactOS Explorer
3 *
4 * Copyright 2013 - Edijs Kolesnikovics
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "precomp.h"
22
23 TASKBAR_SETTINGS TaskBarSettings;
24 const WCHAR szSettingsKey[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer";
25 const WCHAR szAdvancedSettingsKey[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced";
26
27 VOID
28 LoadTaskBarSettings(VOID)
29 {
30 DWORD dwValue = NULL;
31
32 LoadSettingDword(szAdvancedSettingsKey, TEXT("TaskbarSizeMove"), dwValue);
33 TaskBarSettings.bLock = (dwValue != 0) ? TRUE : FALSE;
34
35 LoadSettingDword(szAdvancedSettingsKey, TEXT("ShowSeconds"), dwValue);
36 TaskBarSettings.bShowSeconds = (dwValue != 0) ? TRUE : FALSE;
37
38 LoadSettingDword(szSettingsKey, TEXT("EnableAutotray"), dwValue);
39 TaskBarSettings.bHideInactiveIcons = TRUE;
40
41 LoadSettingDword(szAdvancedSettingsKey, TEXT("TaskbarGlomming"), dwValue);
42 TaskBarSettings.bGroupButtons = (dwValue != 0) ? TRUE : FALSE;
43
44 TaskBarSettings.bShowQuickLaunch = TRUE; //FIXME: Where is this stored, and how?
45
46 /* FIXME: The following settings are stored in stuckrects2, do they have to be load here too? */
47 TaskBarSettings.bShowClock = TRUE;
48 TaskBarSettings.bAutoHide = FALSE;
49 TaskBarSettings.bAlwaysOnTop = FALSE;
50
51 }
52
53 VOID
54 SaveTaskBarSettings(VOID)
55 {
56 SaveSettingDword(szAdvancedSettingsKey, TEXT("TaskbarSizeMove"), TaskBarSettings.bLock);
57 SaveSettingDword(szAdvancedSettingsKey, TEXT("ShowSeconds"), TaskBarSettings.bShowSeconds);
58 SaveSettingDword(szSettingsKey, TEXT("EnableAutotray"), TaskBarSettings.bHideInactiveIcons);
59 SaveSettingDword(szAdvancedSettingsKey, TEXT("TaskbarGlomming"), TaskBarSettings.bGroupButtons);
60
61 /* FIXME: Show Clock, AutoHide and Always on top are stored in the stuckrects2 key but are not written to it with a click on apply. How is this done instead?
62 AutoHide writes something to HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components\0 figure out what and why */
63 }
64
65 BOOL
66 LoadSettingDword(IN LPCWSTR pszKeyName,
67 IN LPCWSTR pszValueName,
68 OUT DWORD &dwValue)
69 {
70 BOOL ret = FALSE;
71 HKEY hKey;
72
73 if (RegOpenKeyW(HKEY_CURRENT_USER, pszKeyName, &hKey) == ERROR_SUCCESS)
74 {
75 DWORD dwValueLength, dwType;
76
77 dwValueLength = sizeof(dwValue);
78 ret = RegQueryValueExW(hKey, pszValueName, NULL, &dwType, (PBYTE)&dwValue, &dwValueLength) == ERROR_SUCCESS && dwType == REG_DWORD;
79
80 RegCloseKey(hKey);
81 }
82
83 return ret;
84 }
85
86 BOOL
87 SaveSettingDword(IN LPCWSTR pszKeyName,
88 IN LPCWSTR pszValueName,
89 IN DWORD dwValue)
90 {
91 BOOL ret = FALSE;
92 HKEY hKey;
93
94 if (RegCreateKeyW(HKEY_CURRENT_USER, pszKeyName, &hKey) == ERROR_SUCCESS)
95 {
96 ret = RegSetValueExW(hKey, pszValueName, 0, REG_DWORD, (PBYTE)&dwValue, sizeof(dwValue)) == ERROR_SUCCESS;
97
98 RegCloseKey(hKey);
99 }
100
101 return ret;
102 }
103
104 /* EOF */