void LoadSettings(void) { HKEY hKey = NULL; HFONT hFont; DWORD dwPointSize = 0; INT base_length, dx, dy; base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN))? GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN); dx = (INT)(base_length * .95); dy = dx * 3 / 4; SetRect( &Globals.main_rect, 0, 0, dx, dy ); if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS) { QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet); QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision); QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement); QueryString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName, sizeof(Globals.lfFont.lfFaceName) / sizeof(Globals.lfFont.lfFaceName[0])); QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic); QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation); QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision); QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily); QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality); QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut); QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline); QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight); QueryDword(hKey, _T("iPointSize"), &dwPointSize); QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines); QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar); QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left); QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top); QueryDword(hKey, _T("iWindowPosDX"), (DWORD*)&dx); QueryDword(hKey, _T("iWindowPosDY"), (DWORD*)&dy); Globals.main_rect.right = Globals.main_rect.left + dx; Globals.main_rect.bottom = Globals.main_rect.top + dy; Globals.bShowStatusBar = !Globals.bShowStatusBar; /* invert value becuase DIALOG_ViewStatusBar will be called to show it*/ if (dwPointSize != 0) Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize); RegCloseKey(hKey); } hFont = CreateFontIndirect(&Globals.lfFont); if (hFont) { if (Globals.hFont) DeleteObject(Globals.hFont); Globals.hFont = hFont; } }
/*********************************************************************** * * NOTEPAD_LoadSettingsFromRegistry * * Load settings from registry HKCU\Software\Microsoft\Notepad. */ void NOTEPAD_LoadSettingsFromRegistry(void) { HKEY hKey = NULL; HFONT hFont; DWORD dwPointSize = 0; INT base_length, dx, dy; base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN)) ? GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN); dx = (INT)(base_length * .95); dy = dx * 3 / 4; SetRect(&Globals.main_rect, 0, 0, dx, dy); if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS) { QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet); QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision); QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement); QueryString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName, ARRAY_SIZE(Globals.lfFont.lfFaceName)); QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic); QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation); QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision); QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily); QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality); QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut); QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline); QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight); QueryDword(hKey, _T("iPointSize"), &dwPointSize); QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines); QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar); QueryString(hKey, _T("szHeader"), Globals.szHeader, ARRAY_SIZE(Globals.szHeader)); QueryString(hKey, _T("szTrailer"), Globals.szFooter, ARRAY_SIZE(Globals.szFooter)); QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMarginLeft); QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMarginTop); QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMarginRight); QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMarginBottom); QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left); QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top); QueryDword(hKey, _T("iWindowPosDX"), (DWORD*)&dx); QueryDword(hKey, _T("iWindowPosDY"), (DWORD*)&dy); Globals.main_rect.right = Globals.main_rect.left + dx; Globals.main_rect.bottom = Globals.main_rect.top + dy; /* invert value because DIALOG_ViewStatusBar will be called to show it */ Globals.bShowStatusBar = !Globals.bShowStatusBar; if (dwPointSize != 0) Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize); else Globals.lfFont.lfHeight = HeightFromPointSize(100); RegCloseKey(hKey); } else { /* If no settings are found in the registry, then use default values */ Globals.lfFont.lfCharSet = 163; Globals.lfFont.lfClipPrecision = 2; Globals.lfFont.lfEscapement = 0; _tcscpy(Globals.lfFont.lfFaceName, _T("Arial")); Globals.lfFont.lfItalic = 0; Globals.lfFont.lfOrientation = 0; Globals.lfFont.lfOutPrecision = 3; Globals.lfFont.lfPitchAndFamily = 34; Globals.lfFont.lfQuality = 1; Globals.lfFont.lfStrikeOut = 0; Globals.lfFont.lfUnderline = 0; Globals.lfFont.lfWeight = 400; Globals.lfFont.lfHeight = HeightFromPointSize(100); } hFont = CreateFontIndirect(&Globals.lfFont); SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE); if (hFont) { if (Globals.hFont) DeleteObject(Globals.hFont); Globals.hFont = hFont; } }