ReactOS  0.4.12-dev-14-gd0c8636
settings.c File Reference
#include "regedit.h"
#include <strsafe.h>
Include dependency graph for settings.c:

Go to the source code of this file.

Classes

struct  RegistryBinaryConfig
 

Functions

DECLSPEC_IMPORT ULONG WINAPIV DbgPrint (PCH 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 ( PCH  Format,
  ... 
)

Referenced by SaveSettings().

◆ LoadSettings()

void LoadSettings ( void  )

Definition at line 62 of file settings.c.

63 {
64  HKEY hKey = NULL;
65  WCHAR szBuffer[MAX_PATH];
66 
68  {
69  RegistryBinaryConfig tConfig;
70  DWORD iBufferSize = sizeof(tConfig);
71  BOOL bVisible = FALSE;
72 
73  if (RegQueryValueExW(hKey, L"View", NULL, NULL, (LPBYTE)&tConfig, &iBufferSize) == ERROR_SUCCESS)
74  {
75  if (iBufferSize == sizeof(tConfig))
76  {
77  RECT rcTemp;
78 
79  /* Update status bar settings */
81  ShowWindow(hStatusBar, (tConfig.StatusBarVisible ? SW_SHOW : SW_HIDE));
82 
83  /* Update listview column width */
84  (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 0, tConfig.NameColumnSize);
85  (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 1, tConfig.TypeColumnSize);
86  (void)ListView_SetColumnWidth(g_pChildWnd->hListWnd, 2, tConfig.DataColumnSize);
87 
88  /* Update treeview (splitter) */
89  GetClientRect(hFrameWnd, &rcTemp);
90  g_pChildWnd->nSplitPos = tConfig.TreeViewSize;
91  ResizeWnd(rcTemp.right, rcTemp.bottom);
92 
93  /* Apply program window settings */
94  tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
95  bVisible = SetWindowPlacement(hFrameWnd, &tConfig.tPlacement);
96  }
97  }
98 
99  /* In case we fail to restore the window, or open the key, show normal */
100  if (!bVisible)
102 
103  /* Restore key position */
104  if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, L"LastKey", szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS)
105  {
106  SelectNode(g_pChildWnd->hTreeWnd, szBuffer);
107  }
108 
109  RegCloseKey(hKey);
110  }
111  else
112  {
113  /* Failed to open key, show normal */
115  }
116 }
ChildWnd * g_pChildWnd
Definition: childwnd.c:23
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:47
#define MF_BYCOMMAND
Definition: winuser.h:202
struct _WINDOWPLACEMENT WINDOWPLACEMENT
#define ERROR_SUCCESS
Definition: deptool.c:10
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SW_HIDE
Definition: winuser.h:762
#define HKEY_CURRENT_USER
Definition: winreg.h:11
HWND hTreeWnd
Definition: main.h:60
HWND hListWnd
Definition: main.h:61
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
LONG right
Definition: windef.h:298
BOOL WINAPI SetWindowPlacement(_In_ HWND hWnd, _In_ const WINDOWPLACEMENT *)
int nSplitPos
Definition: main.h:65
#define ID_VIEW_STATUSBAR
Definition: resource.h:56
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define ListView_SetColumnWidth(hwnd, iCol, cx)
Definition: commctrl.h:2618
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3311
const TCHAR g_szGeneralRegKey[]
Definition: settings.c:16
VOID ResizeWnd(INT cx, INT cy)
Definition: eventvwr.c:3270
smooth NULL
Definition: ftsmooth.c:416
#define SW_SHOW
Definition: winuser.h:769
#define MF_CHECKED
Definition: winuser.h:132
#define COUNT_OF(a)
Definition: main.h:33
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
HWND hStatusBar
Definition: main.cpp:35
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
static const WCHAR L[]
Definition: oid.c:1087
#define ID_VIEW_MENU
Definition: resource.h:25
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define MF_UNCHECKED
Definition: winuser.h:204
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HWND hFrameWnd
Definition: main.c:30
LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
Definition: settings.c:19
#define SW_SHOWNORMAL
Definition: winuser.h:764
HMENU hMenuFrame
Definition: main.c:32
BOOL SelectNode(HWND hwndTV, LPCWSTR keyPath)
Definition: treeview.c:665
LONG bottom
Definition: windef.h:299

◆ SaveSettings()

void SaveSettings ( void  )

Definition at line 118 of file settings.c.

119 {
120  HKEY hKey = NULL;
121 
123  {
124  RegistryBinaryConfig tConfig;
125  DWORD iBufferSize = sizeof(tConfig);
126  WCHAR szBuffer[MAX_PATH]; /* FIXME: a complete registry path can be longer than that */
127  LPCWSTR keyPath, rootName;
128  HKEY hRootKey;
129 
130  /* Save key position */
131  keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
132  rootName = get_root_key_name(hRootKey);
133 
134  /* Load "My Computer" string and complete it */
135  if (LoadStringW(hInst, IDS_MY_COMPUTER, szBuffer, COUNT_OF(szBuffer)) &&
136  SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), L"\\")) &&
137  SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), rootName)) &&
138  SUCCEEDED(StringCbCatW(szBuffer, sizeof(szBuffer), L"\\")))
139  {
140  HRESULT hr = S_OK;
141  if (keyPath)
142  hr = StringCbCatW(szBuffer, sizeof(szBuffer), keyPath);
143  if (SUCCEEDED(hr))
144  RegSetValueExW(hKey, L"LastKey", 0, REG_SZ, (LPBYTE)szBuffer, (DWORD)wcslen(szBuffer) * sizeof(WCHAR));
145  else
146  DbgPrint("err: (%s:%d): Buffer not big enough for '%S + %S'\n", __FILE__, __LINE__, rootName, keyPath);
147  }
148  else
149  {
150  DbgPrint("err: (%s:%d): Buffer not big enough for '%S'\n", __FILE__, __LINE__, rootName);
151  }
152 
153  /* Get statusbar settings */
155 
156  /* Get splitter position */
158 
159  /* Get list view column width*/
163 
164  /* Get program window settings */
165  tConfig.tPlacement.length = sizeof(WINDOWPLACEMENT);
167 
168  /* Save all the data */
169  RegSetValueExW(hKey, L"View", 0, REG_BINARY, (LPBYTE)&tConfig, iBufferSize);
170 
171  RegCloseKey(hKey);
172  }
173 }
ChildWnd * g_pChildWnd
Definition: childwnd.c:23
#define MF_BYCOMMAND
Definition: winuser.h:202
struct _WINDOWPLACEMENT WINDOWPLACEMENT
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define HKEY_CURRENT_USER
Definition: winreg.h:11
HWND hTreeWnd
Definition: main.h:60
UINT WINAPI GetMenuState(_In_ HMENU, _In_ UINT, _In_ UINT)
HWND hListWnd
Definition: main.h:61
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
DECLSPEC_IMPORT ULONG WINAPIV DbgPrint(PCH Format,...)
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
int nSplitPos
Definition: main.h:65
#define ID_VIEW_STATUSBAR
Definition: resource.h:56
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
const TCHAR g_szGeneralRegKey[]
Definition: settings.c:16
smooth NULL
Definition: ftsmooth.c:416
LPCWSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY *phRootKey)
Definition: treeview.c:83
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
#define MF_CHECKED
Definition: winuser.h:132
WINDOWPLACEMENT tPlacement
Definition: settings.c:54
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:4917
#define COUNT_OF(a)
Definition: main.h:33
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDS_MY_COMPUTER
Definition: resource.h:131
static const WCHAR L[]
Definition: oid.c:1087
#define ID_VIEW_MENU
Definition: resource.h:25
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1202
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
LPCWSTR get_root_key_name(HKEY hRootKey)
Definition: childwnd.c:29
HWND hFrameWnd
Definition: main.c:30
#define S_OK
Definition: intsafe.h:59
HINSTANCE hInst
Definition: dxdiag.c:13
HMENU hMenuFrame
Definition: main.c:32
#define ListView_GetColumnWidth(hwnd, iCol)
Definition: commctrl.h:2612
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:57
#define REG_SZ
Definition: layer.c:22

Variable Documentation

◆ g_szGeneralRegKey

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

Definition at line 25 of file settings.c.