2 * ReactOS shell32 - Control Panel
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
33 //#include <process.h>
36 //#include "framewnd.h"
37 //#include "shell32.h"
40 //#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
41 //#include <windows.h>
44 //#define ASSERT assert
46 //#include "control.h"
50 ////////////////////////////////////////////////////////////////////////////////
51 // Global and Local Variables:
54 extern DWORD nListStyle;
55 extern DWORD nSortOrder;
57 ////////////////////////////////////////////////////////////////////////////////
58 // Local module support methods
61 BOOL CheckResult(LONG error)
63 if (error != ERROR_SUCCESS) {
65 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
66 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
67 MessageBox(NULL, msg, szTitle, MB_ICONERROR | MB_OK);
69 MessageBox(NULL, _T("Error"), szTitle, MB_ICONERROR | MB_OK);
76 static BOOL CreateRegistryPath(LPTSTR szRegPath, int nMaxLen)
78 LPTSTR pRegPath = szRegPath;
80 // Initialise registry path string from application PATH and KEY resources
81 int nLength = LoadString(hInst, IDS_APP_REG_PATH, szRegPath, nMaxLen);
82 nLength += LoadString(hInst, IDS_APP_REG_KEY, szRegPath + nLength, nMaxLen - nLength);
83 // ASSERT(nLength < (nMaxLen - 1));
84 szRegPath[nLength] = _T('\\');
86 // walk the registry path string creating the tree if required
87 while ((pRegPath = _tcschr(pRegPath, _T('\\')))) {
91 // Open (or create) the key
92 result = RegCreateKeyEx(HKEY_CURRENT_USER, szRegPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
93 if (!CheckResult(result)) return FALSE;
96 pRegPath = pRegPath + 1;
98 szRegPath[nLength] = _T('\0');
102 BOOL LoadSettings(RECT* prc)
105 TCHAR szRegPath[MAX_LOADSTRING];
106 HMENU hMenuView = GetSubMenu(hMenuFrame, ID_VIEW_MENU);
112 if (!CreateRegistryPath(szRegPath, MAX_LOADSTRING)) return FALSE;
115 result = RegOpenKeyEx(HKEY_CURRENT_USER, szRegPath, 0, KEY_READ, &hKey);
116 if (!CheckResult(result)) return FALSE;
119 dwSize = sizeof(nListStyle);
120 result = RegQueryValueEx(hKey, _T("ListStyle"), NULL, NULL, (LPBYTE)&nListStyle, &dwSize);
121 dwSize = sizeof(nSortOrder);
122 result = RegQueryValueEx(hKey, _T("SortOrder"), NULL, NULL, (LPBYTE)&nSortOrder, &dwSize);
123 dwSize = sizeof(RECT);
124 result = RegQueryValueEx(hKey, _T("WindowPos"), NULL, NULL, (LPBYTE)prc, &dwSize);
125 if (result != ERROR_SUCCESS) {
134 void SaveSettings(RECT* prc)
136 TCHAR szRegPath[MAX_LOADSTRING];
140 if (!CreateRegistryPath(szRegPath, MAX_LOADSTRING)) return;
143 result = RegOpenKeyEx(HKEY_CURRENT_USER, szRegPath, 0, KEY_WRITE, &hKey);
144 if (!CheckResult(result)) return;
147 result = RegSetValueEx(hKey, _T("ListStyle"), 0, REG_DWORD, (LPBYTE)&nListStyle, sizeof(nListStyle));
148 if (!CheckResult(result)) goto abort;
149 result = RegSetValueEx(hKey, _T("SortOrder"), 0, REG_DWORD, (LPBYTE)&nSortOrder, sizeof(nSortOrder));
150 if (!CheckResult(result)) goto abort;
151 result = RegSetValueEx(hKey, _T("WindowPos"), 0, REG_BINARY, (LPBYTE)prc, sizeof(RECT));
152 if (!CheckResult(result)) goto abort;