ReactOS 0.4.16-dev-188-g678aa63
settings.c
Go to the documentation of this file.
1/*
2 * Regedit settings
3 *
4 * Copyright 2012 Edijs Kolesnikovics <terminedijs@yahoo.com>
5 * Copyright 2012 Grégori Macário Harbs <mysoft64bits@gmail.com>
6 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
7 */
8
9#include "regedit.h"
10
11const WCHAR g_szGeneralRegKey[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit";
13
14/*
15VV,VV,VV,VV,WA,WA,WA,WA,WB,WB,WB,WB,R1,R1,R1,R1
16R2,R2,R2,R2,R3,R3,R3,R3,R4,R4,R4,r4,LL,LL,LL,LL
17TT,TT,TT,TT,RR,RR,RR,RR,BB,BB,BB,BB,SS,SS,SS,SS
18NN,NN,NN,NN,KK,KK,KK,KK,DD,DD,DD,DD,SB,SB,SB,SB
19
20VV = Version or Sanity? WINDOWPLACEMENT? (2C?)
21WA = (0=restored / 1=maximized)
22WB = (1=restored / 3=maximized)
23R1 = ???? \
24R2 = ???? | either those are reserved unused or they will
25R3 = ???? | have IP/INFO if connected to remote registry
26R4 = ???? /
27LL = Left position of window
28TT = top position of window
29RR = right position of window
30BB = bottom position of window
31SS = size of key tree view (splitter)
32NN = size of 'name' column
33KK = size of 'type' column (kind)
34DD = size of 'data' coumn
35SB = status bar (1=visible / 0=hidden)
36*/
37
38typedef struct
39{
47
48extern void LoadSettings(void)
49{
50 HKEY hKey = NULL;
51 WCHAR szBuffer[MAX_PATH];
52
54 {
56 DWORD iBufferSize = sizeof(tConfig);
57 BOOL bVisible = FALSE;
58
59 if (RegQueryValueExW(hKey, L"View", NULL, NULL, (LPBYTE)&tConfig, &iBufferSize) == ERROR_SUCCESS)
60 {
61 if (iBufferSize == sizeof(tConfig))
62 {
63 RECT rcTemp;
64
65 /* Update status bar settings */
68
69 /* Update listview column width */
73
74 /* Update treeview (splitter) */
75 GetClientRect(hFrameWnd, &rcTemp);
77 ResizeWnd(rcTemp.right, rcTemp.bottom);
78
79 /* Apply program window settings */
80 tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
81 bVisible = SetWindowPlacement(hFrameWnd, &tConfig.tPlacement);
82 }
83 }
84
85 /* In case we fail to restore the window, or open the key, show normal */
86 if (!bVisible)
88
89 /* Restore key position */
90 if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, L"LastKey", szBuffer, ARRAY_SIZE(szBuffer)) == ERROR_SUCCESS)
91 {
93 }
94
96 }
97 else
98 {
99 /* Failed to open key, show normal */
101 }
102}
103
104extern void SaveSettings(void)
105{
106 HKEY hKey = NULL;
107
109 {
110 RegistryBinaryConfig tConfig;
111 DWORD iBufferSize = sizeof(tConfig);
112 WCHAR szBuffer[MAX_PATH]; /* FIXME: a complete registry path can be longer than that */
113 LPCWSTR keyPath, rootName;
114 HKEY hRootKey;
115
116 /* Save key position */
117 keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
118 rootName = get_root_key_name(hRootKey);
119
120 /* Load "My Computer" string and complete it */
121 if (LoadStringW(hInst, IDS_MY_COMPUTER, szBuffer, ARRAY_SIZE(szBuffer)) &&
122 SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), L"\\")) &&
123 SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), rootName)) &&
124 SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), L"\\")))
125 {
126 HRESULT hr = S_OK;
127 if (keyPath)
128 hr = StringCbCatW(szBuffer, sizeof(szBuffer), keyPath);
129 if (SUCCEEDED(hr))
130 RegSetValueExW(hKey, L"LastKey", 0, REG_SZ, (LPBYTE)szBuffer, (DWORD)wcslen(szBuffer) * sizeof(WCHAR));
131 else
132 DbgPrint("err: (%s:%d): Buffer not big enough for '%S + %S'\n", __FILE__, __LINE__, rootName, keyPath);
133 }
134 else
135 {
136 DbgPrint("err: (%s:%d): Buffer not big enough for '%S'\n", __FILE__, __LINE__, rootName);
137 }
138
139 /* Get statusbar settings */
141
142 /* Get splitter position */
144
145 /* Get list view column width*/
149
150 /* Get program window settings */
151 tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
153
154 /* Save all the data */
155 RegSetValueExW(hKey, L"View", 0, REG_BINARY, (LPBYTE)&tConfig, iBufferSize);
156
158 }
159}
160/* EOF */
LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
Definition: settings.c:19
void SaveSettings(void)
Definition: settings.c:115
const TCHAR g_szGeneralRegKey[]
Definition: settings.c:16
void LoadSettings(void)
Definition: settings.c:53
ChildWnd * g_pChildWnd
Definition: childwnd.c:13
LPCWSTR get_root_key_name(HKEY hRootKey)
Definition: childwnd.c:76
HWND hFrameWnd
Definition: main.c:22
HMENU hMenuFrame
Definition: main.c:24
HWND hStatusBar
Definition: main.c:23
BOOL SelectNode(HWND hwndTV, LPCWSTR keyPath)
Definition: treeview.c:766
#define ARRAY_SIZE(A)
Definition: main.h:20
LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY *phRootKey)
Definition: treeview.c:73
#define IDS_MY_COMPUTER
Definition: resource.h:82
#define ID_VIEW_STATUSBAR
Definition: resource.h:40
#define ID_VIEW_MENU
Definition: resource.h:12
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1201
#define MAX_PATH
Definition: compat.h:34
HINSTANCE hInst
Definition: dxdiag.c:13
VOID ResizeWnd(INT cx, INT cy)
Definition: eventvwr.c:3267
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define DbgPrint
Definition: hal.h:12
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define REG_SZ
Definition: layer.c:22
#define REG_BINARY
Definition: nt_native.h:1496
CONST CHAR * PCCH
Definition: ntbasedef.h:392
#define L(x)
Definition: ntvdm.h:50
#define ListView_GetColumnWidth(hwnd, iCol)
Definition: commctrl.h:2647
#define ListView_SetColumnWidth(hwnd, iCol, cx)
Definition: commctrl.h:2653
#define WINAPIV
Definition: sdbpapi.h:64
#define DECLSPEC_IMPORT
Definition: rpc.h:78
HRESULT hr
Definition: shlfolder.c:183
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
int nSplitPos
Definition: main.h:56
HWND hTreeWnd
Definition: main.h:50
HWND hListWnd
Definition: main.h:51
WINDOWPLACEMENT tPlacement
Definition: settings.c:40
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define SW_SHOWNORMAL
Definition: winuser.h:773
#define SW_HIDE
Definition: winuser.h:771
#define MF_BYCOMMAND
Definition: winuser.h:202
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
UINT WINAPI GetMenuState(_In_ HMENU, _In_ UINT, _In_ UINT)
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define MF_CHECKED
Definition: winuser.h:132
#define MF_UNCHECKED
Definition: winuser.h:204
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define SW_SHOW
Definition: winuser.h:778
struct _WINDOWPLACEMENT WINDOWPLACEMENT
BOOL WINAPI SetWindowPlacement(_In_ HWND hWnd, _In_ const WINDOWPLACEMENT *)
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185