ReactOS 0.4.15-dev-7924-g5949c20
general.cpp
Go to the documentation of this file.
1/*
2 * 'General' tab property sheet of Folder Options
3 *
4 * Copyright 2007 Johannes Anderwald <johannes.anderwald@reactos.org>
5 * Copyright 2016-2018 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include "precomp.h"
23
25
26typedef struct REGSHELLSTATE
27{
31
32#define REGSHELLSTATE_SIZE 0x24
33
35 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer";
36
38// Shell settings
39
40static void
42{
43 ZeroMemory(&rss, sizeof(rss));
45
48
51 rss.ss.fShowInfoTip = TRUE;
52
53 rss.ss.iSortDirection = 1;
54 rss.ss.version = 0xD;
55 rss.ss.fStartPanelOn = TRUE;
56}
57
58// bDoubleClick is TRUE if "Double-click to open an item (single-click to select)".
59// bDoubleClick is FALSE if "Single-click to open an item (point to select)".
61// API Monitor:
62// SHLWAPI.dll RegOpenKeyExW ( 0x000000c8, NULL, 0, MAXIMUM_ALLOWED, 0x00def234 ) ERROR_SUCCESS 0.0000243
63// SHLWAPI.dll RegSetValueExW ( 0x000003e8, "ShellState", 0, REG_BINARY, 0x000c2050, 36 ) ERROR_SUCCESS 0.0001028
64// SHLWAPI.dll RegCloseKey ( 0x000003e8 ) ERROR_SUCCESS 0.0000081
65// Explorer.EXE SHSettingsChanged ( 0, "ShellState" ) 0.0000131
66static BOOL
67IntSetShellStateSettings(BOOL bDoubleClick, BOOL bUseCommonTasks)
68{
69 REGSHELLSTATE rss;
70 DWORD dwSize = sizeof(rss);
71 LSTATUS nStatus;
72
73 // read ShellState
76 L"ShellState",
77 NULL,
78 &rss,
79 &dwSize);
80 if (nStatus != ERROR_SUCCESS || rss.dwSize < REGSHELLSTATE_SIZE)
81 {
83 }
84
85 // update ShellState
86 rss.ss.fDoubleClickInWebView = (bDoubleClick ? TRUE : FALSE);
87 rss.ss.fWebView = (bUseCommonTasks ? TRUE : FALSE);
88
89 // write ShellState
93 L"ShellState",
95 &rss,
96 dwSize);
97 if (nStatus != ERROR_SUCCESS)
98 return FALSE;
99
100 SHSettingsChanged(0, L"ShellState");
101 return TRUE;
102}
103
105// API Monitor:
106// SHLWAPI.dll RegOpenKeyExW ( 0x000000c8, NULL, 0, MAXIMUM_ALLOWED, 0x0007e484 ) ERROR_SUCCESS 0.0000388
107// SHLWAPI.dll RegQueryValueExW ( 0x000005a8, "ShellState", NULL, 0x0007e474, 0x000c2050, 0x0007e4fc ) ERROR_SUCCESS 0.0000271
108// SHLWAPI.dll RegCloseKey ( 0x000005a8 ) ERROR_SUCCESS 0.0000112
109static BOOL
110IntGetShellStateSettings(BOOL& bDoubleClick, BOOL& bUseCommonTasks)
111{
112 REGSHELLSTATE rss;
113 DWORD dwSize = sizeof(rss);
114 LSTATUS nStatus;
115 bDoubleClick = TRUE;
116 bUseCommonTasks = FALSE;
117
118 // read ShellState
120 L"ShellState", NULL, &rss, &dwSize);
121 if (nStatus != ERROR_SUCCESS || rss.dwSize < REGSHELLSTATE_SIZE)
122 return FALSE;
123
124 bDoubleClick = !!rss.ss.fDoubleClickInWebView;
125 bUseCommonTasks = !!rss.ss.fWebView;
126 return TRUE;
127}
128
129// bIconUnderline is TRUE if "Underline icon titles only when I point at them".
130// bIconUnderline is FALSE if "Underline icon titles consistent with my browser".
132// API Monitor:
133// SHELL32.dll SHRegGetUSValueW ( "Software\Microsoft\Windows\CurrentVersion\Explorer", "IconUnderline", NULL, 0x00d2f324, 0x00d2f328, FALSE, 0x00d2f32c, 4 ) ERROR_SUCCESS 0.0002484
134// SHELL32.dll IsDlgButtonChecked ( 0x0005009e, 30104 ) BST_CHECKED 0.0000212
135// SHELL32.dll SHRegSetUSValueW ( "Software\Microsoft\Windows\CurrentVersion\Explorer", "IconUnderline", 0, 0x00d2f314, 4, 6 ) ERROR_SUCCESS 0.0008300
136// Explorer.EXE SHSettingsChanged ( 0, "Software\Microsoft\Windows\CurrentVersion\Explorer\IconUnderline" ) 0.0000092
137static BOOL IntSetUnderlineState(BOOL bIconUnderline)
138{
140 DWORD dwValue = (bIconUnderline ? 3 : 2), dwSize = sizeof(DWORD);
143 if (Status != ERROR_SUCCESS)
144 return FALSE;
145
146 SHSettingsChanged(0, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\IconUnderline");
147 return TRUE;
148}
149
151{
152 DWORD dwValue, dwDefault = 2, dwSize = sizeof(DWORD);
153 SHRegGetUSValue(s_pszExplorerKey, L"IconUnderline", NULL, &dwValue, &dwSize, FALSE, &dwDefault, sizeof(DWORD));
154 return dwValue == 3;
155}
156
157// bNewWindowMode is TRUE if "Open each folder in its own window".
158// bNewWindowMode is FALSE if "Open each folder in the same window".
160// API Monitor:
161// SHELL32.dll RegCreateKeyExW ( HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState", 0, NULL, 0, KEY_SET_VALUE, NULL, 0x00d2f2b8, NULL ) ERROR_SUCCESS 0.0000455
162// SHELL32.dll RegSetValueExW ( 0x00000854, "Settings", 0, REG_BINARY, 0x0210f170, 12 ) ERROR_SUCCESS 0.0001472
163// SHELL32.dll RegSetValueExW ( 0x00000854, "FullPath", 0, REG_DWORD, 0x00d2f2ac, 4 ) ERROR_SUCCESS 0.0000168
164// SHELL32.dll RegCloseKey ( 0x00000854 ) ERROR_SUCCESS 0.0000000
165static BOOL IntSetNewWindowMode(BOOL bNewWindowMode)
166{
168 if (!ReadCabinetState(&cs, sizeof(cs)))
169 return FALSE;
170
171 cs.fNewWindowMode = (bNewWindowMode ? TRUE : FALSE);
172 return WriteCabinetState(&cs);
173}
174
176{
178 if (!ReadCabinetState(&cs, sizeof(cs)))
179 return FALSE;
180
181 return !!cs.fNewWindowMode;
182}
183
185// GeneralDlg
186
187typedef struct GENERAL_DIALOG
188{
193
194static VOID
196{
197 HICON hTaskIcon = NULL, hFolderIcon = NULL, hClickIcon = NULL;
198 LPTSTR lpTaskIconName = NULL, lpFolderIconName = NULL, lpClickIconName = NULL;
199
200 // Show task setting icon.
205
206 if (lpTaskIconName)
207 {
208 hTaskIcon = (HICON)LoadImage(shell32_hInstance, lpTaskIconName,
210 if (hTaskIcon)
211 {
212 HWND hwndTaskIcon = GetDlgItem(hDlg, IDC_FOLDER_OPTIONS_TASKICON);
213 SendMessage(hwndTaskIcon, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hTaskIcon);
214 }
215 }
216
217 // Show Folder setting icons
222
223 if (lpFolderIconName)
224 {
225 hFolderIcon = (HICON)LoadImage(shell32_hInstance, lpFolderIconName,
227 if (hFolderIcon)
228 {
229 HWND hwndFolderIcon = GetDlgItem(hDlg, IDC_FOLDER_OPTIONS_FOLDERICON);
230 SendMessage(hwndFolderIcon, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hFolderIcon);
231 }
232 }
233
234 // Show click setting icon
239
240 if (lpClickIconName)
241 {
242 hClickIcon = (HICON)LoadImage(shell32_hInstance, lpClickIconName,
244 if (hClickIcon)
245 {
246 HWND hwndClickIcon = GetDlgItem(hDlg, IDC_FOLDER_OPTIONS_CLICKICON);
247 SendMessage(hwndClickIcon, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hClickIcon);
248 }
249 }
250
251 // Replace icons
252 if (hTaskIcon)
253 {
254 DestroyIcon(pGeneral->hTaskIcon);
255 pGeneral->hTaskIcon = hTaskIcon;
256 }
257 if (hFolderIcon)
258 {
259 DestroyIcon(pGeneral->hFolderIcon);
260 pGeneral->hFolderIcon = hFolderIcon;
261 }
262 if (hClickIcon)
263 {
264 DestroyIcon(pGeneral->hClickIcon);
265 pGeneral->hClickIcon = hClickIcon;
266 }
267
268 if (nCtrlID == IDC_FOLDER_OPTIONS_SINGLECLICK)
269 {
272 }
273
274 if (nCtrlID == IDC_FOLDER_OPTIONS_DOUBLECLICK)
275 {
279 }
280}
281
282static void
283GeneralDlg_StoreToUI(HWND hwndDlg, BOOL bDoubleClick, BOOL bUseCommonTasks,
284 BOOL bUnderline, BOOL bNewWindowMode, PGENERAL_DIALOG pGeneral)
285{
286 if (bUseCommonTasks)
288 else
290
291 if (bDoubleClick)
293 else
295
296 if (bNewWindowMode)
298 else
300
301 if (!bDoubleClick)
302 {
305 if (bUnderline)
307 else
309 }
310 else
311 {
315 }
316}
317
318static BOOL
320{
321 BOOL bDoubleClick = TRUE;
322 BOOL bUseCommonTasks = FALSE;
323 BOOL bUnderline = IntGetUnderlineState();
324 BOOL bNewWindowMode = IntGetNewWindowMode();
325
326 IntGetShellStateSettings(bDoubleClick, bUseCommonTasks);
327
328 GeneralDlg_StoreToUI(hwndDlg, bDoubleClick, bUseCommonTasks, bUnderline, bNewWindowMode, pGeneral);
329 GeneralDlg_UpdateIcons(hwndDlg, 0, pGeneral);
330
331 return TRUE;
332}
333
334static void
336{
337 // default values
338 BOOL bDoubleClick = TRUE;
339 BOOL bUseCommonTasks = FALSE;
340 BOOL bUnderline = FALSE;
341 BOOL bNewWindowMode = FALSE;
342
343 GeneralDlg_StoreToUI(hwndDlg, bDoubleClick, bUseCommonTasks, bUnderline, bNewWindowMode, pGeneral);
344 GeneralDlg_UpdateIcons(hwndDlg, 0, pGeneral);
345}
346
347static BOOL
349{
351 BOOL bUseCommonTasks = (IsDlgButtonChecked(hwndDlg, IDC_FOLDER_OPTIONS_COMMONTASKS) == BST_CHECKED);
353 BOOL bNewWindowMode = !(IsDlgButtonChecked(hwndDlg, IDC_FOLDER_OPTIONS_SAMEWINDOW) == BST_CHECKED);
354
355 IntSetUnderlineState(bUnderline);
356 IntSetNewWindowMode(bNewWindowMode);
357 IntSetShellStateSettings(bDoubleClick, bUseCommonTasks);
358 return TRUE;
359}
360
363 HWND hwndDlg,
364 UINT uMsg,
367{
368 static GENERAL_DIALOG general;
369
370 switch (uMsg)
371 {
372 case WM_INITDIALOG:
373 general.hTaskIcon = NULL;
374 general.hFolderIcon = NULL;
375 general.hClickIcon = NULL;
376 return GeneralDlg_OnInitDialog(hwndDlg, &general);
377
378 case WM_COMMAND:
379 switch (LOWORD(wParam))
380 {
389 if (HIWORD(wParam) == BN_CLICKED)
390 {
391 GeneralDlg_UpdateIcons(hwndDlg, LOWORD(wParam), &general);
392
393 // Enable the 'Apply' button
394 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
395 }
396 break;
398 if (HIWORD(wParam) == BN_CLICKED)
399 {
400 GeneralDlg_OnRestoreDefaults(hwndDlg, &general);
401
402 // Enable the 'Apply' button
403 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
404 }
405 break;
406 }
407 break;
408
409 case WM_NOTIFY:
410 {
411 LPNMHDR pnmh = (LPNMHDR)lParam;
412
413 switch (pnmh->code)
414 {
415 case PSN_SETACTIVE:
416 break;
417
418 case PSN_APPLY:
419 return GeneralDlg_OnApply(hwndDlg, &general);
420 }
421 break;
422 }
423
424 case WM_DESTROY:
425 DestroyIcon(general.hTaskIcon);
426 DestroyIcon(general.hFolderIcon);
427 DestroyIcon(general.hClickIcon);
428 break;
429
430 default:
431 return FALSE;
432 }
433 return FALSE;
434}
#define shell32_hInstance
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define ERROR_SUCCESS
Definition: deptool.c:10
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1236
DWORD WINAPI SHSetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue, DWORD dwType, LPCVOID pvData, DWORD cbData)
Definition: reg.c:1306
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
static void IntGetDefaultShellState(REGSHELLSTATE &rss)
Definition: general.cpp:41
static BOOL IntGetNewWindowMode(VOID)
Definition: general.cpp:175
static BOOL IntGetUnderlineState(VOID)
Definition: general.cpp:150
#define REGSHELLSTATE_SIZE
Definition: general.cpp:32
static BOOL IntSetShellStateSettings(BOOL bDoubleClick, BOOL bUseCommonTasks)
Definition: general.cpp:67
static BOOL IntSetUnderlineState(BOOL bIconUnderline)
Definition: general.cpp:137
static BOOL GeneralDlg_OnInitDialog(HWND hwndDlg, PGENERAL_DIALOG pGeneral)
Definition: general.cpp:319
struct GENERAL_DIALOG * PGENERAL_DIALOG
static const LPCWSTR s_pszExplorerKey
Definition: general.cpp:34
static BOOL IntGetShellStateSettings(BOOL &bDoubleClick, BOOL &bUseCommonTasks)
Definition: general.cpp:110
static VOID GeneralDlg_UpdateIcons(HWND hDlg, UINT nCtrlID, PGENERAL_DIALOG pGeneral)
Definition: general.cpp:195
struct REGSHELLSTATE * PREGSHELLSTATE
static void GeneralDlg_OnRestoreDefaults(HWND hwndDlg, PGENERAL_DIALOG pGeneral)
Definition: general.cpp:335
static BOOL IntSetNewWindowMode(BOOL bNewWindowMode)
Definition: general.cpp:165
static BOOL GeneralDlg_OnApply(HWND hwndDlg, PGENERAL_DIALOG pGeneral)
Definition: general.cpp:348
INT_PTR CALLBACK FolderOptionsGeneralDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: general.cpp:362
struct REGSHELLSTATE REGSHELLSTATE
static void GeneralDlg_StoreToUI(HWND hwndDlg, BOOL bDoubleClick, BOOL bUseCommonTasks, BOOL bUnderline, BOOL bNewWindowMode, PGENERAL_DIALOG pGeneral)
Definition: general.cpp:283
#define cs
Definition: i386-dis.c:442
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static HICON
Definition: imagelist.c:84
unsigned int UINT
Definition: ndis.h:50
#define REG_BINARY
Definition: nt_native.h:1496
#define DWORD
Definition: nt_native.h:44
#define REG_NONE
Definition: nt_native.h:1492
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSN_APPLY
Definition: prsht.h:117
#define PSN_SETACTIVE
Definition: prsht.h:115
#define WM_NOTIFY
Definition: richedit.h:61
BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
Definition: shellord.c:1609
BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
Definition: shellord.c:1656
#define SHRegSetUSValue
Definition: shlwapi.h:556
#define SHRegGetUSValue
Definition: shlwapi.h:534
#define SHREGSET_HKLM
Definition: shlwapi.h:313
#define SHREGSET_FORCE_HKCU
Definition: shlwapi.h:312
BOOL WINAPI SHSettingsChanged(LPCVOID unused, LPCWSTR pszKey)
Definition: shpolicy.c:174
#define IDC_FOLDER_OPTIONS_CLASSICFOLDERS
Definition: shresdef.h:415
#define IDC_FOLDER_OPTIONS_ULBROWSER
Definition: shresdef.h:420
#define IDC_FOLDER_OPTIONS_SINGLECLICK
Definition: shresdef.h:418
#define IDC_FOLDER_OPTIONS_COMMONTASKS
Definition: shresdef.h:414
#define IDI_SHELL_OPEN_IN_SOME_WINDOW
Definition: shresdef.h:650
#define IDC_FOLDER_OPTIONS_SAMEWINDOW
Definition: shresdef.h:416
#define IDC_FOLDER_OPTIONS_FOLDERICON
Definition: shresdef.h:412
#define IDI_SHELL_OPEN_IN_NEW_WINDOW
Definition: shresdef.h:651
#define IDI_SHELL_CLASSIC_FOLDERS
Definition: shresdef.h:649
#define IDI_SHELL_SINGLE_CLICK_TO_OPEN
Definition: shresdef.h:652
#define IDC_FOLDER_OPTIONS_CLICKICON
Definition: shresdef.h:413
#define IDC_FOLDER_OPTIONS_DOUBLECLICK
Definition: shresdef.h:419
#define IDI_SHELL_DOUBLE_CLICK_TO_OPEN
Definition: shresdef.h:653
#define IDC_FOLDER_OPTIONS_TASKICON
Definition: shresdef.h:411
#define IDC_FOLDER_OPTIONS_ULPOINT
Definition: shresdef.h:421
#define IDC_FOLDER_OPTIONS_RESTORE
Definition: shresdef.h:422
#define IDC_FOLDER_OPTIONS_OWNWINDOW
Definition: shresdef.h:417
#define IDI_SHELL_SHOW_COMMON_TASKS
Definition: shresdef.h:648
HICON hFolderIcon
Definition: general.cpp:190
HICON hClickIcon
Definition: general.cpp:191
HICON hTaskIcon
Definition: general.cpp:189
DWORD dwSize
Definition: general.cpp:28
SHELLSTATE ss
Definition: general.cpp:29
BOOL fShowExtensions
Definition: shlobj.h:1533
BOOL fWebView
Definition: shlobj.h:1546
BOOL fShowCompColor
Definition: shlobj.h:1537
BOOL fShowInfoTip
Definition: shlobj.h:1544
UINT version
Definition: shlobj.h:1556
int iSortDirection
Definition: shlobj.h:1555
BOOL fShowAllObjects
Definition: shlobj.h:1532
BOOL fDoubleClickInWebView
Definition: shlobj.h:1538
BOOL fStartPanelOn
Definition: shlobj.h:1559
UINT code
Definition: winuser.h:3159
int32_t INT_PTR
Definition: typedefs.h:64
#define HIWORD(l)
Definition: typedefs.h:247
#define ZeroMemory
Definition: winbase.h:1712
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define IMAGE_ICON
Definition: winuser.h:212
#define WM_COMMAND
Definition: winuser.h:1740
#define WM_INITDIALOG
Definition: winuser.h:1739
#define STM_SETIMAGE
Definition: winuser.h:2093
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
struct tagNMHDR * LPNMHDR
#define SendMessage
Definition: winuser.h:5843
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HWND WINAPI GetParent(_In_ HWND)
#define LoadImage
Definition: winuser.h:5815
BOOL WINAPI CheckRadioButton(_In_ HWND, _In_ int, _In_ int, _In_ int)
#define LR_DEFAULTCOLOR
Definition: winuser.h:1087
#define BN_CLICKED
Definition: winuser.h:1925
#define WM_DESTROY
Definition: winuser.h:1609
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define BST_CHECKED
Definition: winuser.h:197
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2053
CHAR * LPTSTR
Definition: xmlstorage.h:192
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185