/* * Winefile * * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs * Copyright 2006 Jason Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include "winefile.h" static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\', 'W','i','n','e','\\', 'W','i','n','e','F','i','l','e','\0'}; static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'}; static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'}; static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'}; static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'}; static const WCHAR reg_logfont[] = { 'l','o','g','f','o','n','t','\0'}; /* save program settings to the registry */ void save_registry_settings(void) { WINDOWINFO wi; HKEY hKey; INT width, height; LOGFONT logfont; wi.cbSize = sizeof(WINDOWINFO); GetWindowInfo(Globals.hMainWnd, &wi); width = wi.rcWindow.right - wi.rcWindow.left; height = wi.rcWindow.bottom - wi.rcWindow.top; if (RegOpenKeyExW(HKEY_CURRENT_USER, registry_key, 0, KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) { /* Unable to save registry settings - try to create key */ if (RegCreateKeyExW(HKEY_CURRENT_USER, registry_key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL) != ERROR_SUCCESS) { /* FIXME: Cannot create key */ return; } } /* Save all of the settings */ RegSetValueExW(hKey, reg_start_x, 0, REG_DWORD, (LPBYTE) &wi.rcWindow.left, sizeof(DWORD)); RegSetValueExW(hKey, reg_start_y, 0, REG_DWORD, (LPBYTE) &wi.rcWindow.top, sizeof(DWORD)); RegSetValueExW(hKey, reg_width, 0, REG_DWORD, (LPBYTE) &width, sizeof(DWORD)); RegSetValueExW(hKey, reg_height, 0, REG_DWORD, (LPBYTE) &height, sizeof(DWORD)); GetObject(Globals.hfont, sizeof(logfont), &logfont); RegSetValueExW(hKey, reg_logfont, 0, REG_BINARY, (LPBYTE) &logfont, sizeof(LOGFONT)); /* TODO: Save more settings here (List vs. Detailed View, etc.) */ RegCloseKey(hKey); } /* read program settings from the registry */ void load_registry_settings(struct WINDOW_OPTIONS* pOpts) { DWORD size; DWORD type; HKEY hKey; LOGFONT logfont; RegOpenKeyExW(HKEY_CURRENT_USER, registry_key, 0, KEY_QUERY_VALUE, &hKey); size = sizeof(DWORD); if (RegQueryValueExW(hKey, reg_start_x, NULL, &type, (LPBYTE) &pOpts->start_x, &size) != ERROR_SUCCESS) pOpts->start_x = CW_USEDEFAULT; if (RegQueryValueExW(hKey, reg_start_y, NULL, &type, (LPBYTE) &pOpts->start_y, &size) != ERROR_SUCCESS) pOpts->start_y = CW_USEDEFAULT; if (RegQueryValueExW(hKey, reg_width, NULL, &type, (LPBYTE) &pOpts->width, &size) != ERROR_SUCCESS) pOpts->width = CW_USEDEFAULT; if (RegQueryValueExW(hKey, reg_height, NULL, &type, (LPBYTE) &pOpts->height, &size) != ERROR_SUCCESS) pOpts->height = CW_USEDEFAULT; size = sizeof(logfont); if (RegQueryValueExW(hKey, reg_logfont, NULL, &type, (LPBYTE) &logfont, &size) != ERROR_SUCCESS) GetObject(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont); RegCloseKey(hKey); Globals.hfont = CreateFontIndirect(&logfont); }