From 100504d2f589aff7c19b8a4dd449c9ccea8941b8 Mon Sep 17 00:00:00 2001 From: Petrichor Park Date: Tue, 18 Jul 2023 12:02:41 -0500 Subject: [PATCH] notepad: Use GetDpiForWindow(). Instead of querying the registry, just calls `GetDpiForWindow`. Winecfg's DPI slider sets `Control Panel\\Desktop\\LogPixels`. See `programs/winecfg/x11drvdlg.c` Notepad queries `Software\\Fonts\\LogPixels`, and so doesn't pick up on the change. --- programs/notepad/dialog.c | 2 +- programs/notepad/main.c | 31 ++----------------------------- programs/notepad/main.h | 1 - 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/programs/notepad/dialog.c b/programs/notepad/dialog.c index d9269b31b93..3865bc55426 100644 --- a/programs/notepad/dialog.c +++ b/programs/notepad/dialog.c @@ -958,7 +958,7 @@ VOID DIALOG_FilePrint(VOID) /* Create a font for the printer resolution */ lfFont = Globals.lfFont; - lfFont.lfHeight = MulDiv(lfFont.lfHeight, GetDeviceCaps(printer.hDC, LOGPIXELSY), get_dpi()); + lfFont.lfHeight = MulDiv(lfFont.lfHeight, GetDeviceCaps(printer.hDC, LOGPIXELSY), GetDpiForWindow(Globals.hMainWnd)); /* Make the font a bit lighter */ lfFont.lfWeight -= 100; hTextFont = CreateFontIndirectW(&lfFont); diff --git a/programs/notepad/main.c b/programs/notepad/main.c index 829cd7af33b..7d961086821 100644 --- a/programs/notepad/main.c +++ b/programs/notepad/main.c @@ -81,33 +81,6 @@ VOID SetFileNameAndEncoding(LPCWSTR szFileName, ENCODING enc) Globals.encFile = enc; } -/****************************************************************************** - * get_dpi - * - * Get the dpi from registry HKCC\Software\Fonts\LogPixels. - */ -DWORD get_dpi(void) -{ - static const WCHAR dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'}; - static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'}; - DWORD dpi = 96; - HKEY hkey; - - if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS) - { - DWORD type, size, new_dpi; - - size = sizeof(new_dpi); - if(RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (LPBYTE)&new_dpi, &size) == ERROR_SUCCESS) - { - if(type == REG_DWORD && new_dpi != 0) - dpi = new_dpi; - } - RegCloseKey(hkey); - } - return dpi; -} - void UpdateStatusBar(void) { int currentLine; @@ -210,7 +183,7 @@ static VOID NOTEPAD_SaveSettingToRegistry(void) #undef SET_NOTEPAD_REG /* Store the current value as 10 * twips */ - data = MulDiv(abs(Globals.lfFont.lfHeight), 720 , get_dpi()); + data = MulDiv(abs(Globals.lfFont.lfHeight), 720, GetDpiForWindow(Globals.hMainWnd)); RegSetValueExW(hkey, value_iPointSize, 0, REG_DWORD, (LPBYTE)&data, sizeof(DWORD)); RegSetValueExW(hkey, value_lfFaceName, 0, REG_SZ, (LPBYTE)&Globals.lfFont.lfFaceName, @@ -309,7 +282,7 @@ static VOID NOTEPAD_LoadSettingFromRegistry(void) if(RegQueryValueExW(hkey, value_iPointSize, 0, &type, (LPBYTE)&point_size, &size) == ERROR_SUCCESS) if(type == REG_DWORD) /* The value is stored as 10 * twips */ - Globals.lfFont.lfHeight = -MulDiv(abs(point_size), get_dpi(), 720); + Globals.lfFont.lfHeight = -MulDiv(abs(point_size), GetDpiForWindow(Globals.hMainWnd), 720); size = sizeof(Globals.lfFont.lfFaceName); if(RegQueryValueExW(hkey, value_lfFaceName, 0, &type, (LPBYTE)&data_helper, &size) == ERROR_SUCCESS) diff --git a/programs/notepad/main.h b/programs/notepad/main.h index 906b0925077..f197ac1752c 100644 --- a/programs/notepad/main.h +++ b/programs/notepad/main.h @@ -76,7 +76,6 @@ extern NOTEPAD_GLOBALS Globals; VOID SetFileNameAndEncoding(LPCWSTR szFileName, ENCODING enc); void NOTEPAD_DoFind(FINDREPLACEW *fr); -DWORD get_dpi(void); void UpdateStatusBar(void); void updateWindowSize(int width, int height); LRESULT CALLBACK EDIT_CallBackProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);