00001 /* 00002 * Winefile 00003 * 00004 * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs 00005 * Copyright 2006 Jason Green 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include "winefile.h" 00023 00024 00025 static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\', 00026 'W','i','n','e','\\', 00027 'W','i','n','e','F','i','l','e','\0'}; 00028 static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'}; 00029 static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'}; 00030 static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'}; 00031 static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'}; 00032 static const WCHAR reg_logfont[] = { 'l','o','g','f','o','n','t','\0'}; 00033 00034 00035 /* save program settings to the registry */ 00036 00037 void save_registry_settings(void) 00038 { 00039 WINDOWINFO wi; 00040 HKEY hKey; 00041 INT width, height; 00042 LOGFONT logfont; 00043 00044 wi.cbSize = sizeof(WINDOWINFO); 00045 GetWindowInfo(Globals.hMainWnd, &wi); 00046 width = wi.rcWindow.right - wi.rcWindow.left; 00047 height = wi.rcWindow.bottom - wi.rcWindow.top; 00048 00049 if (RegOpenKeyExW(HKEY_CURRENT_USER, registry_key, 00050 0, KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) 00051 { 00052 /* Unable to save registry settings - try to create key */ 00053 if (RegCreateKeyExW(HKEY_CURRENT_USER, registry_key, 00054 0, NULL, REG_OPTION_NON_VOLATILE, 00055 KEY_SET_VALUE, NULL, &hKey, NULL) != ERROR_SUCCESS) 00056 { 00057 /* FIXME: Cannot create key */ 00058 return; 00059 } 00060 } 00061 00062 /* Save all of the settings */ 00063 RegSetValueExW(hKey, reg_start_x, 0, REG_DWORD, 00064 (LPBYTE) &wi.rcWindow.left, sizeof(DWORD)); 00065 RegSetValueExW(hKey, reg_start_y, 0, REG_DWORD, 00066 (LPBYTE) &wi.rcWindow.top, sizeof(DWORD)); 00067 RegSetValueExW(hKey, reg_width, 0, REG_DWORD, 00068 (LPBYTE) &width, sizeof(DWORD)); 00069 RegSetValueExW(hKey, reg_height, 0, REG_DWORD, 00070 (LPBYTE) &height, sizeof(DWORD)); 00071 GetObject(Globals.hfont, sizeof(logfont), &logfont); 00072 RegSetValueExW(hKey, reg_logfont, 0, REG_BINARY, 00073 (LPBYTE) &logfont, sizeof(LOGFONT)); 00074 00075 /* TODO: Save more settings here (List vs. Detailed View, etc.) */ 00076 RegCloseKey(hKey); 00077 } 00078 00079 00080 /* read program settings from the registry */ 00081 00082 void load_registry_settings(struct WINDOW_OPTIONS* pOpts) 00083 { 00084 DWORD size; 00085 DWORD type; 00086 HKEY hKey; 00087 LOGFONT logfont; 00088 00089 RegOpenKeyExW(HKEY_CURRENT_USER, registry_key, 0, KEY_QUERY_VALUE, &hKey); 00090 00091 size = sizeof(DWORD); 00092 00093 if (RegQueryValueExW(hKey, reg_start_x, NULL, &type, 00094 (LPBYTE) &pOpts->start_x, &size) != ERROR_SUCCESS) 00095 pOpts->start_x = CW_USEDEFAULT; 00096 00097 if (RegQueryValueExW(hKey, reg_start_y, NULL, &type, 00098 (LPBYTE) &pOpts->start_y, &size) != ERROR_SUCCESS) 00099 pOpts->start_y = CW_USEDEFAULT; 00100 00101 if (RegQueryValueExW(hKey, reg_width, NULL, &type, 00102 (LPBYTE) &pOpts->width, &size) != ERROR_SUCCESS) 00103 pOpts->width = CW_USEDEFAULT; 00104 00105 if (RegQueryValueExW(hKey, reg_height, NULL, &type, 00106 (LPBYTE) &pOpts->height, &size) != ERROR_SUCCESS) 00107 pOpts->height = CW_USEDEFAULT; 00108 00109 size = sizeof(logfont); 00110 00111 if (RegQueryValueExW(hKey, reg_logfont, NULL, &type, 00112 (LPBYTE) &logfont, &size) != ERROR_SUCCESS) 00113 GetObject(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont); 00114 00115 RegCloseKey(hKey); 00116 00117 Globals.hfont = CreateFontIndirect(&logfont); 00118 }
Winefile Source Code Documentation
generated on 15.09.2008 by |