From 982d2a82391269bc5c104b6965548df070357628 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Fri, 24 Nov 2023 21:10:09 +0200 Subject: [PATCH] Fix font size calculation in custom dialogs. --- od-win32/hardfile_win32.cpp | 4 ++-- od-win32/win32gui.cpp | 8 ++++---- od-win32/win32gui.h | 2 +- od-win32/win32gui_extra.cpp | 11 +++++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/od-win32/hardfile_win32.cpp b/od-win32/hardfile_win32.cpp index 0eaf877e..a4a763a0 100644 --- a/od-win32/hardfile_win32.cpp +++ b/od-win32/hardfile_win32.cpp @@ -1436,7 +1436,7 @@ static int gethdfchs(HWND hDlg, struct uae_driveinfo *udi, HANDLE h, int *cylsp, err = -15; goto end; } - font = CreateFont(getscaledfontsize(-1), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console")); + font = CreateFont(getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console")); if (font) SendMessage(GetDlgItem(hwnd, IDD_CHSQUERY), WM_SETFONT, WPARAM(font), FALSE); while (chsdialogactive == 1) { @@ -1669,7 +1669,7 @@ doout: hdini = ini; hwnd = CustomCreateDialog(&res, IDD_DISKINFO, hDlg, StringBoxDialogProc); if (hwnd != NULL) { - HFONT font = CreateFont (getscaledfontsize(-1), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console")); + HFONT font = CreateFont (getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console")); if (font) SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE); SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text); diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index b3b37b85..ace85e35 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -2627,7 +2627,7 @@ void gui_infotextbox(HWND hDlg, const TCHAR *text) if (hwnd == NULL) return; - HFONT font = CreateFont (getscaledfontsize(-1), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console")); + HFONT font = CreateFont (getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console")); if (font) SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE); SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text); @@ -2725,7 +2725,7 @@ static void infofloppy (HWND hDlg, int n) if (hwnd == NULL) return; - HFONT font = CreateFont (getscaledfontsize(-1), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console")); + HFONT font = CreateFont (getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console")); if (font) SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE); SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text); @@ -8065,10 +8065,10 @@ static INT_PTR CALLBACK AboutDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM pages[ABOUT_ID] = hDlg; currentpage = ABOUT_ID; - font1 = CreateFont(getscaledfontsize(-1) * 3, 0, 0, 0, 0, + font1 = CreateFont(getscaledfontsize(-1, hDlg) * 3, 0, 0, 0, 0, 0, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY, FF_DONTCARE, _T("Segoe UI")); - font2 = CreateFont(getscaledfontsize(-1) * 2, 0, 0, 0, 0, + font2 = CreateFont(getscaledfontsize(-1, hDlg) * 2, 0, 0, 0, 0, 0, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY, FF_DONTCARE, _T("Segoe UI")); diff --git a/od-win32/win32gui.h b/od-win32/win32gui.h index 20cf2cf1..b5152f8d 100644 --- a/od-win32/win32gui.h +++ b/od-win32/win32gui.h @@ -137,7 +137,7 @@ extern void scaleresource_init(const TCHAR*, int); extern int scaleresource_choosefont (HWND hDlg, int fonttype); extern void scaleresource_setdefaults(HWND); extern void scalaresource_listview_font_info(int*); -extern int getscaledfontsize(int size); +extern int getscaledfontsize(int size, HWND); extern void scaleresource_modification(HWND); extern bool show_box_art(const TCHAR*, const TCHAR*); extern void move_box_art_window(void); diff --git a/od-win32/win32gui_extra.cpp b/od-win32/win32gui_extra.cpp index 852588cd..c5bc09fb 100644 --- a/od-win32/win32gui_extra.cpp +++ b/od-win32/win32gui_extra.cpp @@ -983,7 +983,7 @@ static void scalechildwindows(struct newresource *nr) } SetFocus(nw->hwnd); if (!SetWindowPos(nw->hwnd, HWND_TOP, x, y, w, h, SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | SWP_DEFERERASE)) { - write_log("scalechildwindows %d/%d: ERROR %d", i, nr->hwndcnt, GetLastError()); + write_log("scalechildwindows %d/%d: ERROR %d\n", i, nr->hwndcnt, GetLastError()); } if (disable) { EnableWindow(nw->hwnd, FALSE); @@ -1207,7 +1207,7 @@ void freescaleresource (struct newresource *ns) ns->size = 0; } -int getscaledfontsize(int size) +int getscaledfontsize(int size, HWND hwnd) { int lm = 72; @@ -1215,9 +1215,12 @@ int getscaledfontsize(int size) size = fontsize_gui; if (!dpi_aware_v2) { - HDC hdc = GetDC(NULL); + HDC hdc = GetDC(hwnd); lm = GetDeviceCaps(hdc, LOGPIXELSY); - ReleaseDC(NULL, hdc); + ReleaseDC(hwnd, hdc); + } else if (hwnd) { + HMONITOR m = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); + lm = getdpiformonitor(m); } size = -MulDiv(size, lm, 72); return size; -- 2.47.3