Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensettings.c
Go to the documentation of this file.
00001 /* 00002 * Notepad (settings.c) 00003 * 00004 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch> 00005 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr> 00006 * Copyright 2002 Andriy Palamarchuk 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #include <notepad.h> 00024 00025 static LPCTSTR s_szRegistryKey = _T("Software\\Microsoft\\Notepad"); 00026 00027 00028 static LONG HeightFromPointSize(DWORD dwPointSize) 00029 { 00030 LONG lHeight; 00031 HDC hDC; 00032 00033 hDC = GetDC(NULL); 00034 lHeight = -MulDiv(dwPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 720); 00035 ReleaseDC(NULL, hDC); 00036 00037 return lHeight; 00038 } 00039 00040 static DWORD PointSizeFromHeight(LONG lHeight) 00041 { 00042 DWORD dwPointSize; 00043 HDC hDC; 00044 00045 hDC = GetDC(NULL); 00046 dwPointSize = -MulDiv(lHeight, 720, GetDeviceCaps(hDC, LOGPIXELSY)); 00047 ReleaseDC(NULL, hDC); 00048 00049 /* round to nearest multiple of 10 */ 00050 dwPointSize += 5; 00051 dwPointSize -= dwPointSize % 10; 00052 00053 return dwPointSize; 00054 } 00055 00056 static BOOL QueryGeneric(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, 00057 LPVOID pvResult, DWORD dwResultSize) 00058 { 00059 DWORD dwType, cbData; 00060 LPVOID *pTemp = _alloca(dwResultSize); 00061 00062 ZeroMemory(pTemp, dwResultSize); 00063 00064 cbData = dwResultSize; 00065 if (RegQueryValueEx(hKey, pszValueNameT, NULL, &dwType, (LPBYTE) pTemp, &cbData) != ERROR_SUCCESS) 00066 return FALSE; 00067 00068 if (dwType != dwExpectedType) 00069 return FALSE; 00070 00071 memcpy(pvResult, pTemp, cbData); 00072 return TRUE; 00073 } 00074 00075 static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult) 00076 { 00077 return QueryGeneric(hKey, pszValueName, REG_DWORD, pdwResult, sizeof(*pdwResult)); 00078 } 00079 00080 static BOOL QueryByte(HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult) 00081 { 00082 DWORD dwResult; 00083 if (!QueryGeneric(hKey, pszValueName, REG_DWORD, &dwResult, sizeof(dwResult))) 00084 return FALSE; 00085 if (dwResult >= 0x100) 00086 return FALSE; 00087 *pbResult = (BYTE) dwResult; 00088 return TRUE; 00089 } 00090 00091 static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult) 00092 { 00093 DWORD dwResult; 00094 if (!QueryDword(hKey, pszValueName, &dwResult)) 00095 return FALSE; 00096 *pbResult = dwResult ? TRUE : FALSE; 00097 return TRUE; 00098 } 00099 00100 static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize) 00101 { 00102 return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(TCHAR)); 00103 } 00104 00105 void LoadSettings(void) 00106 { 00107 HKEY hKey = NULL; 00108 HFONT hFont; 00109 DWORD dwPointSize = 0; 00110 INT base_length, dx, dy; 00111 00112 base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN))? 00113 GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN); 00114 00115 dx = (INT)(base_length * .95); 00116 dy = dx * 3 / 4; 00117 SetRect( &Globals.main_rect, 0, 0, dx, dy ); 00118 00119 if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS) 00120 { 00121 QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet); 00122 QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision); 00123 QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement); 00124 QueryString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName, sizeof(Globals.lfFont.lfFaceName) / sizeof(Globals.lfFont.lfFaceName[0])); 00125 QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic); 00126 QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation); 00127 QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision); 00128 QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily); 00129 QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality); 00130 QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut); 00131 QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline); 00132 QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight); 00133 QueryDword(hKey, _T("iPointSize"), &dwPointSize); 00134 QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines); 00135 QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar); 00136 00137 QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left); 00138 QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top); 00139 QueryDword(hKey, _T("iWindowPosDX"), (DWORD*)&dx); 00140 QueryDword(hKey, _T("iWindowPosDY"), (DWORD*)&dy); 00141 00142 Globals.main_rect.right = Globals.main_rect.left + dx; 00143 Globals.main_rect.bottom = Globals.main_rect.top + dy; 00144 00145 Globals.bShowStatusBar = !Globals.bShowStatusBar; /* invert value becuase DIALOG_ViewStatusBar will be called to show it*/ 00146 00147 if (dwPointSize != 0) 00148 Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize); 00149 00150 RegCloseKey(hKey); 00151 } 00152 00153 hFont = CreateFontIndirect(&Globals.lfFont); 00154 if (hFont) 00155 { 00156 if (Globals.hFont) 00157 DeleteObject(Globals.hFont); 00158 Globals.hFont = hFont; 00159 } 00160 } 00161 00162 static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue) 00163 { 00164 return RegSetValueEx(hKey, pszValueNameT, 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(dwValue)) == ERROR_SUCCESS; 00165 } 00166 00167 static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue) 00168 { 00169 return RegSetValueEx(hKey, pszValueNameT, 0, REG_SZ, (LPBYTE) pszValue, (DWORD) _tcslen(pszValue) * sizeof(*pszValue)) == ERROR_SUCCESS; 00170 } 00171 00172 void SaveSettings(void) 00173 { 00174 HKEY hKey; 00175 DWORD dwDisposition; 00176 00177 GetWindowRect(Globals.hMainWnd, &Globals.main_rect); 00178 00179 if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) 00180 == ERROR_SUCCESS) 00181 { 00182 SaveDword(hKey, _T("lfCharSet"), Globals.lfFont.lfCharSet); 00183 SaveDword(hKey, _T("lfClipPrecision"), Globals.lfFont.lfClipPrecision); 00184 SaveDword(hKey, _T("lfEscapement"), Globals.lfFont.lfEscapement); 00185 SaveString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName); 00186 SaveDword(hKey, _T("lfItalic"), Globals.lfFont.lfItalic); 00187 SaveDword(hKey, _T("lfOrientation"), Globals.lfFont.lfOrientation); 00188 SaveDword(hKey, _T("lfOutPrecision"), Globals.lfFont.lfOutPrecision); 00189 SaveDword(hKey, _T("lfPitchAndFamily"), Globals.lfFont.lfPitchAndFamily); 00190 SaveDword(hKey, _T("lfQuality"), Globals.lfFont.lfQuality); 00191 SaveDword(hKey, _T("lfStrikeOut"), Globals.lfFont.lfStrikeOut); 00192 SaveDword(hKey, _T("lfUnderline"), Globals.lfFont.lfUnderline); 00193 SaveDword(hKey, _T("lfWeight"), Globals.lfFont.lfWeight); 00194 SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight)); 00195 SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0); 00196 SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0); 00197 SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left); 00198 SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top); 00199 SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left); 00200 SaveDword(hKey, _T("iWindowPosDY"), Globals.main_rect.bottom - Globals.main_rect.top); 00201 RegCloseKey(hKey); 00202 } 00203 00204 } Generated on Sun May 27 2012 04:16:30 for ReactOS by
1.7.6.1
|