ReactOS 0.4.15-dev-7906-g1b85a5f
settings.c File Reference
#include "regedit.h"
Include dependency graph for settings.c:

Go to the source code of this file.

Classes

struct  RegistryBinaryConfig
 

Functions

DECLSPEC_IMPORT ULONG WINAPIV DbgPrint (PCCH Format,...)
 
void LoadSettings (void)
 
void SaveSettings (void)
 

Variables

const WCHAR g_szGeneralRegKey [] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit"
 

Function Documentation

◆ DbgPrint()

DECLSPEC_IMPORT ULONG WINAPIV DbgPrint ( PCCH  Format,
  ... 
)

Definition at line 432 of file debug.c.

433{
434 return 0;
435}

◆ LoadSettings()

void LoadSettings ( void  )

Definition at line 61 of file settings.c.

62{
63 HKEY hKey = NULL;
64 WCHAR szBuffer[MAX_PATH];
65
67 {
69 DWORD iBufferSize = sizeof(tConfig);
70 BOOL bVisible = FALSE;
71
72 if (RegQueryValueExW(hKey, L"View", NULL, NULL, (LPBYTE)&tConfig, &iBufferSize) == ERROR_SUCCESS)
73 {
74 if (iBufferSize == sizeof(tConfig))
75 {
76 RECT rcTemp;
77
78 /* Update status bar settings */
80 ShowWindow(hStatusBar, (tConfig.StatusBarVisible ? SW_SHOW : SW_HIDE));
81
82 /* Update listview column width */
83 (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 0, tConfig.NameColumnSize);
84 (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 1, tConfig.TypeColumnSize);
85 (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 2, tConfig.DataColumnSize);
86
87 /* Update treeview (splitter) */
88 GetClientRect(hFrameWnd, &rcTemp);
89 g_pChildWnd->nSplitPos = tConfig.TreeViewSize;
90 ResizeWnd(rcTemp.right, rcTemp.bottom);
91
92 /* Apply program window settings */
93 tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
94 bVisible = SetWindowPlacement(hFrameWnd, &tConfig.tPlacement);
95 }
96 }
97
98 /* In case we fail to restore the window, or open the key, show normal */
99 if (!bVisible)
101
102 /* Restore key position */
103 if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, L"LastKey", szBuffer, ARRAY_SIZE(szBuffer)) == ERROR_SUCCESS)
104 {
105 SelectNode(g_pChildWnd->hTreeWnd, szBuffer);
106 }
107
109 }
110 else
111 {
112 /* Failed to open key, show normal */
114 }
115}
LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
Definition: settings.c:19
const TCHAR g_szGeneralRegKey[]
Definition: settings.c:16
ChildWnd * g_pChildWnd
Definition: childwnd.c:23
HWND hFrameWnd
Definition: main.c:35
HMENU hMenuFrame
Definition: main.c:37
HWND hStatusBar
Definition: main.c:36
BOOL SelectNode(HWND hwndTV, LPCWSTR keyPath)
Definition: treeview.c:785
#define ARRAY_SIZE(A)
Definition: main.h:33
#define ID_VIEW_STATUSBAR
Definition: resource.h:54
#define ID_VIEW_MENU
Definition: resource.h:25
#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 RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define MAX_PATH
Definition: compat.h:34
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 L(x)
Definition: ntvdm.h:50
#define ListView_SetColumnWidth(hwnd, iCol, cx)
Definition: commctrl.h:2648
int nSplitPos
Definition: main.h:69
HWND hTreeWnd
Definition: main.h:63
HWND hListWnd
Definition: main.h:64
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define SW_SHOWNORMAL
Definition: winuser.h:770
#define SW_HIDE
Definition: winuser.h:768
#define MF_BYCOMMAND
Definition: winuser.h:202
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#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:775
struct _WINDOWPLACEMENT WINDOWPLACEMENT
BOOL WINAPI SetWindowPlacement(_In_ HWND hWnd, _In_ const WINDOWPLACEMENT *)
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ SaveSettings()

void SaveSettings ( void  )

Definition at line 117 of file settings.c.

118{
119 HKEY hKey = NULL;
120
122 {
123 RegistryBinaryConfig tConfig;
124 DWORD iBufferSize = sizeof(tConfig);
125 WCHAR szBuffer[MAX_PATH]; /* FIXME: a complete registry path can be longer than that */
126 LPCWSTR keyPath, rootName;
127 HKEY hRootKey;
128
129 /* Save key position */
130 keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
131 rootName = get_root_key_name(hRootKey);
132
133 /* Load "My Computer" string and complete it */
134 if (LoadStringW(hInst, IDS_MY_COMPUTER, szBuffer, ARRAY_SIZE(szBuffer)) &&
135 SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), L"\\")) &&
136 SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), rootName)) &&
137 SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), L"\\")))
138 {
139 HRESULT hr = S_OK;
140 if (keyPath)
141 hr = StringCbCatW(szBuffer, sizeof(szBuffer), keyPath);
142 if (SUCCEEDED(hr))
143 RegSetValueExW(hKey, L"LastKey", 0, REG_SZ, (LPBYTE)szBuffer, (DWORD)wcslen(szBuffer) * sizeof(WCHAR));
144 else
145 DbgPrint("err: (%s:%d): Buffer not big enough for '%S + %S'\n", __FILE__, __LINE__, rootName, keyPath);
146 }
147 else
148 {
149 DbgPrint("err: (%s:%d): Buffer not big enough for '%S'\n", __FILE__, __LINE__, rootName);
150 }
151
152 /* Get statusbar settings */
154
155 /* Get splitter position */
157
158 /* Get list view column width*/
162
163 /* Get program window settings */
164 tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
166
167 /* Save all the data */
168 RegSetValueExW(hKey, L"View", 0, REG_BINARY, (LPBYTE)&tConfig, iBufferSize);
169
171 }
172}
LPCWSTR get_root_key_name(HKEY hRootKey)
Definition: childwnd.c:29
LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY *phRootKey)
Definition: treeview.c:88
#define IDS_MY_COMPUTER
Definition: resource.h:129
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 RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1201
HINSTANCE hInst
Definition: dxdiag.c:13
#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
#define ListView_GetColumnWidth(hwnd, iCol)
Definition: commctrl.h:2642
HRESULT hr
Definition: shlfolder.c:183
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
WINDOWPLACEMENT tPlacement
Definition: settings.c:53
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)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Variable Documentation

◆ g_szGeneralRegKey

const WCHAR g_szGeneralRegKey[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit"

Definition at line 24 of file settings.c.